Problem with autoFitColumns()

Hello,

I have problem with autoFitColumns() on Worksheet. Columns size is changed, but inaccurately. Text in cells is wrapped.

I am using Aspose Cells for Java v. 2.1.0.13

Thanks

Hi,

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells for Java. We have already made a few changes regarding AutoFitColumns API in this release. If you still face the issue, please share your sample code and excel files (template file and output file) and we will check it soon.

Thank You & Best Regards,

Hello,

In attached version it is still broken.

But I found, what is causing this problem. I have table with header in first row. If I set style of header cells to style.setTextWrapped(true);, then it´s broken. When I remove this line, everything works fine..

Hi,

Have you found the problem? In which version this will be patched?

Hi,

Thank you for considering Aspose.

Please share your sample code and excel files (template file and output file) to reproduce the issue. We will check it soon.

Thank You & Best Regards,

Hi,
In attachment there is maven project with one test. This test creates file c:/test.xls
You can run this test by calling: mvn test
As you see, text that shoudn´t be wrapped is actualy wrapped, although I called autoFitColums()…

Hi,

Thank you for sharing the sample project.

We will look into it and get back to you soon.

Thank You & Best Regards,

Hi,

Thanks for your project.

We have tested it and could not understand your demand. For your information, if you apply Style.setTextWrapped(true) for the header row(cell), so, when you call autoFitColumns(), the text would be wrapped in the header row cell obviously. This behavior is same as MS Excel. We could not understand why you are saying the text should not be wrapped anymore. If you don’t want to wrap the text in the header cell, just comment the line in the method like getDefaultHeaderStyle() in AsposeExcelTable.java file:
// style.setTextWrapped(true);


Thanks for your understanding!

Hi,

I think it should be wrapped only if there are multiple words (spaces between). If i have for example text "name" it wouldn´t be

na

me

Or am I wrong?

Thanks

Hi,

Well, space (b/w the words) is not necessarily required to implement Wrap text feature. You may simply confirm/check it in MS Excel (2003, 2007) manually (e.g insert a text without space into a cell) and you can see the text does wrapped in the cell.
e.g

Open a new workbook in MS Excel 2007.
Insert some dummy data into A1 cell in the worksheet i.e…, “kadsfj_asjdfl_ajsdlfj_asdjflaj”.
Now right-click on the cell and click “Format Cells…”, set the Wrap text in Alignment tab.
click OK.


Thank you.

You are right..

Excel has strange behavior in this case - if column width is wider than width of non-wrapped text, then autofit shrink column to width of non-wrapped text and text is not wrapped.

But when column width is closer than width of non-wrapped text (text is wrapped), then autofit doesn´t spread column to width of non-wrapped text and remains wrapped.

So autofit function acts differently based on initial width of column.

Thanks for clearing this - my misunderstand..