I am looping over each worksheet in a workbook, trying to auto fit all columns on the worksheet. The autoFitColumns method does not appear to be auto fitting anything. Here is my code. Does this look inaccurate? This is the Java component, running on Linux.
Please download and try the latest version:
Aspose.Cells for Java 7.1.1 and see if it works fine.
If the problem still occurs, then please provide us your source xls/xlsx and output xls/xlsx files.
We will look into it and help you asap.
Thanks for the response. I am using Cells 7.1.1. I downloaded it maybe a week ago. I have attached the source file, and output file.
I have tested your file with the latest version and found it is working fine.
Please see the code below and the output file.
Please make sure you are using all the latest version of prerequistes jars needed by aspose.cells jar file, you can find them in the latest zip:
Aspose.Cells for Java 7.1.1
String filePath = “F:\Shak-Data-RW\Downloads\TermFilePN_20120204-20120210_Report.xls”;
Workbook workbook = new Workbook(filePath);
Worksheet sheet = workbook.getWorksheets().get(0);
Alright. I can see that it is applying the auto fit column width but I don’t think the auto fit width makes the columns wide enough. I feel like the C# component does a better version of this. Is it possible that these are not quite doing auto fit width in the same way?
You can also adjust width according to your choice.
Please use sheet.getCells().setColumnWidth() method to set the width as you want.
The better approach will be that you first auto fit columns, then read the width of your column using getColumnWidth, then after adding some value inside it, set it using setColumnWidth.
I had thought of that. I am just honestly not convinced that autofit is working as intended. Look at this resulting PDF. I applied autofit to these columns. I don’t think any of these columns look like they’ve been autofit well.
Thanks for your feedback.
I have forwarded your issue to development team and logged this issue in our database.
We will look into it and get back to you asap.
This issue has been logged as CELLSJAVA-40142.
It definitely looks better, in my opinion. I still have a sheet that results in a few #'s, because the column didn’t get wide enough, but I’m not that picky. This has at least made it so that it looks like auto-fit is actually being applied, whereas the previous version did not look like it.