Free Support Forum - aspose.com

AutoFitRow not making rows big enough with wrap text on

I’m using Excel 2003 and Aspose.Cells version 4.6. I have wrap text turned on and anywhere from a few characters to 1,000+ characters in each cell. AutoFitRow is not making the row tall enough to display all of the text in the cell. When I call AutoFitRow in the Excel application, the row height adjusts to display the values in the cells appropriately.

Hi,

Well, I tested Worksheet.AutoFitRow() method and it works fine same as MS Excel. Following is my testing code and the output file is also attached.

Sample code:

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Sheet1"];
Cells cell = ws.Cells;
cell[0, 0].PutValue("Voor meer informatie, nga naar");
cell[0, 0].Style.IsTextWrapped = true;
ws.AutoFitRow(0);
wb.Save("f:\\test\\outfit.xls", FileFormatType.Excel2003);

And kindly try the attached version (4.6.0.6).
If you still find any issue, kindly post your template file with sample codes here, we will check it soon.
Thank you.

I was changing the default font size of the workbook and that appears to affect the AutoFitRow method. I tested my code without the font size change and the AutoFitRow appears to work correctly.

Her is the code I am using:

' set workbook default style
objDefaultStyle = objWorkbook.DefaultStyle
With objDefaultStyle
.Font.Size = 8
.Font.Name = "Arial"
End With
objWorkbook.DefaultStyle = objDefaultStyle
objDefaultStyle = Nothing

Hi,

Thanks for sharing further details.

Yes, we found the issue regarding AutoFitRow when changing default font attributes. I think the row height are not extended enough to show the contents fully when applying AutoFitRow operation. Anyways we will look into it and figure it out soon.

I think for the time being you may try to set/extend some column width(s) to show the contents properly while we fix the issue.

Thank you.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Please try the attached latest fix of Aspose.Cells. We have fixed the bug regarding AutoFit row height.

Thank You & Best Regards,

Thank you for the fix, but I am still seeing the same results. My code is below and I have attached the created file. Note that the top line of the cell text is missing and when you AutoFitRow in Excel, it is displayed.

Dim strText As String
Dim ws As Aspose.Cells.Worksheet = objWorkbook.Worksheets("Sheet1")
Dim cell As Aspose.Cells.Cells = ws.Cells
With cell(0, 0)
strText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
strText &= vbLf & vbLf
strText &= "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
.PutValue(strText)
.Style.IsTextWrapped = True
.Style.Font.Size = 8
.Style.VerticalAlignment = Aspose.Cells.TextAlignmentType.Bottom
End With
ws.Cells.SetColumnWidth(0, 50)
ws.AutoFitRows()

' send the file back to the browser
objWorkbook.Save("AutoFitRow Test.xls", Aspose.Cells.FileFormatType.Excel2003, _
Aspose.Cells.SaveType.OpenInExcel, HttpContext.Current.Response)

Hi, xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" <o:p></o:p>

Thank you for sharing the generated file and sample code. We have found the issue after an initial test. We will fix it soon.

Thank you for your patience,

Hi,

Please try the attached version (4.6.0.8), we have fixed the issue.

Thank you.

Thanks again for the new version. I tested it and am still seeing some situations where the top line of text in the cell is not displayed. It seems to happen when there is more text, although I'm not exactly sure what the real reason might be. I have attached sample code again which is the same as above, with just more text being writen to the cell. Also, please see the attached spreadsheet demonstrating the results.

Dim strText As String
Dim ws As Aspose.Cells.Worksheet = objWorkbook.Worksheets("Sheet1")
Dim cell As Aspose.Cells.Cells = ws.Cells
With cell(0, 0)
strText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
strText &= vbLf & vbLf
strText &= "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
strText &= vbLf & vbLf
strText &= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
'strText &= vbLf & vbLf
'strText &= "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
.PutValue(strText)
.Style.IsTextWrapped = True
.Style.Font.Size = 8
.Style.VerticalAlignment = Aspose.Cells.TextAlignmentType.Bottom
End With
ws.Cells.SetColumnWidth(0, 50)
ws.AutoFitRows()

' send the file back to the browser
objWorkbook.Save("AutoFitRow Test.xls", Aspose.Cells.FileFormatType.Excel2003, _
Aspose.Cells.SaveType.OpenInExcel, HttpContext.Current.Response)

Hi,

Thank you for sharing the generated file and sample code. We have found the issue after an initial test and we will fix it and get back to you soon.

Thank You & Best Regards,

Hi,

Please try the attached version, we have fixed this bug. It is to be noted here, the row height would be 193.5 after performing auto fit operation by Aspose.Cells, which is a bit larger than the row height (191.25) performed the operation manually in MS Excel. I think it's a minor case and not a big difference, it not it?

Thank you.

Thank you for your continued work on this issue. I know there is a limit of around 1,024 characters after which Excel itslef does not properly autofit rows, but I increased the text in the cell once more to less than this limit and I am still getting the top line of text not bieng displayed. It appears that cells containing less text are autofitting properly. Might I ask you to take one more look? I have attached sample code below. I am testing the dll with other data than that in the sample code I am providing and am seeing the same results on cells with larger amounts of text. Thanks.

Dim strText As String
Dim ws As Aspose.Cells.Worksheet = objWorkbook.Worksheets("Sheet1")
Dim cell As Aspose.Cells.Cells = ws.Cells
With cell(0, 0)
strText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
strText &= vbLf & vbLf
strText &= "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
strText &= vbLf & vbLf
strText &= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
strText &= vbLf & vbLf
strText &= "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
.PutValue(strText)
.Style.IsTextWrapped = True
.Style.Font.Size = 8
.Style.VerticalAlignment = Aspose.Cells.TextAlignmentType.Bottom
End With
ws.Cells.SetColumnWidth(0, 50)
ws.AutoFitRows()

' send the file back to the browser
objWorkbook.Save("AutoFitRow Test.xls", Aspose.Cells.FileFormatType.Excel2003, _
Aspose.Cells.SaveType.OpenInExcel, HttpContext.Current.Response)

Hi,

Well, I don't find the problem you have mentioned. Attached is my output file. Please make sure that you are using the lastest version / fix (4.6.0.9).

Thank you.

My apologies… I left out that I am changing the default font size before I execute the code I posted. If I do NOT do that, I get the same results that you did… the row is autofit correctly. However, if I DO change the default font size, the top line of text is not displayed (as in the file I attached on my previous post). Thanks again for your continued attention to this matter.

Hi,

Thanks for sharing further details.

Yes, we checked, changing the default style of the workbook may produce the issue you have talked about.

We will soon look into it to figure it out.

Thank you.

I am also experiencing this issue and awaiting a final fix.

Thanks.

Hi

We will provide a fix in the next week for most of us (developers in our team) are on holidays for the spring festival.

Sorry for any inconvenience.

Hi,

We have fixed the issue, kindly try the attached version. We will further look into how to auto-fit row heights similar (exactly 100%) to what MS Excel does.

Thank you.

Thanks for the new version. It looks like it is working in many cases but there are still some instances where the top line of text is not displayed. I have done a fair amount of testing with different amounts of text and using uppercase vs. lowercase characters. I can’t seem to find any one situation that causes the row not to be fit correctly. I would like to say, though, that this version is working much better than the one I started with and I would be appreciative of any continued work on the issue. Thanks again for your help.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback. We will try to improve this feature more in our future release. We will appreciate your input too in this regard. Please share you template file and code for any issue you still face in this regard and we will figure it soon.

Thank You & Best Regards,