unvell / ReoGrid

Fast and powerful .NET spreadsheet component, support data format, freeze, outline, formula calculation, chart, script execution and etc. Compatible with Excel 2007 (.xlsx) format and working on .NET 3.5 (or client profile), WPF and Android platform.
https://reogrid.net
MIT License
1.32k stars 390 forks source link

How to display full text beyond cell limits? #502

Closed lotuslakestudio closed 1 year ago

lotuslakestudio commented 1 year ago

I'm using this software to creat a .xlsx file like this 2 Yet the production of this software is this 1

So, how to get the right format as shown in the first picture? Thanks in advance.

jingwood commented 1 year ago

You have to enable the setting:

Worksheet.EnableSettings(WorksheetSettings.View_AllowCellTextOverflow);

And avoid to set cells background color.

lotuslakestudio commented 1 year ago

It seems the above code isn't working. The texts are still being trimmed at the cell border. I'm using Win10, Visual studio 2022 community, .net framework 4.8.

lotuslakestudio commented 1 year ago

I found the problem. This bug occurs because I introduced another 3rd program to generate .xlsx files, which named "closedxml". When I fill the cells by ReoGrid code, the format is correct.

jingwood commented 1 year ago

So if the problem has been resolved, you can consider to close this issue.

lotuslakestudio commented 1 year ago

Although the origin of the problem has been discovered, I don't know how to solve it. I tried another program "NPOI". The program generated long text beyond cell limits can not be displayed correctly in ReoGrid, either. Can you fix that? ---------------- by NPOI --------------------

XSSFWorkbook workbook = new XSSFWorkbook();
ISheet ws = workbook.CreateSheet("sheet1");            
XSSFRichTextString rts = new XSSFRichTextString("Some text which is very long that exceeds the boundary");
ws.CreateRow(0).CreateCell(0).SetCellValue(rts1);
workbook.Write("c:\\test.xlsx");

jingwood commented 1 year ago

Can you please provide the xlsx file?

lotuslakestudio commented 1 year ago

temp.xlsx As above.

lotuslakestudio commented 1 year ago

Another problem found. When I'm using this.reoGridControl1.CurrentWorksheet.Cells["A1"].Data ="very looooooooong text" The cell looks good. But if i'm using unvell.ReoGrid.Drawing.RichText rt = new unvell.ReoGrid.Drawing.RichText(); rt.Regular("very looooooooong text"); this.reoGridControl1.Worksheets[0].Cells["A1"].Data = rt; The same problem happens. The text beyond cell boundary is trimmed.

lotuslakestudio commented 1 year ago

I solved this problem finally.

foreach (var sheet in this.reoGridControl1.Worksheets)
 {
       sheet.EnableSettings(WorksheetSettings.View_AllowCellTextOverflow);
       for (int r = sheet.UsedRange.Row; r <= sheet.UsedRange.EndRow; r++)
            for (int c = sheet.UsedRange.Col; c <= sheet.UsedRange.EndCol; c++)                    
                if (sheet.GetCell(r, c) != null && sheet.GetCell(r, c).Data is unvell.ReoGrid.Drawing.RichText)
      (sheet.GetCell(r, c).Data as unvell.ReoGrid.Drawing.RichText).Overflow = true;
}