autoFitColumns not working when used with different font settings

I am using Aspose.Cells 7.7.1 library and trying to use autoFitColumns() for the sheet. It is not adjusting the width properly for the cells having font size set as bold.


In some cases where we have combination of both font settings and merge columns autoFit is not behaving properly. Could you please check?

Below is the code snippet for your reference:
try {
//Instantiating a Workbook object
Workbook workbook = new Workbook();

//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();

Style colStyle;
Font font;

//Adding a some value to “A1” cell
Cell cell = cells.get(“A1”);
cell.setValue(“Some long text need to test auto fit COLUMN”);
colStyle = cell.getStyle();
font = colStyle.getFont();
font.setSize(8);
font.setName(“Verdana”);
font.setBold(true);
cell.setStyle(colStyle);

//Adding a some value to “B1” cell
cell = cells.get(“B1”);
cell.setValue(“Some long text”);
colStyle = cell.getStyle();
font = colStyle.getFont();
font.setSize(8);
font.setBold(true);
font.setName(“Verdana”);
cell.setStyle(colStyle);

//Adding a some value to “A2” cell
cell = cells.get(“A2”);
cells.merge(1, 0, 1, 3);
cell.setValue(“Some long text need to test”);
colStyle = cell.getStyle();
font = colStyle.getFont();
font.setSize(8);
font.setName(“Verdana”);
cell.setStyle(colStyle);

//Adding a some value to “B3” cell
cell = cells.get(“B3”);
cell.setValue(“Some long text need to test”);
colStyle = cell.getStyle();
font = colStyle.getFont();
font.setSize(8);
font.setName(“Verdana”);
font.setBold(true);
cell.setStyle(colStyle);

//Adding a some value to “C3” cell
cell = cells.get(“C3”);
cell.setValue(“Some long text need to test autofit”);
colStyle = cell.getStyle();
font = colStyle.getFont();
font.setSize(8);
font.setName(“Verdana”);
cell.setStyle(colStyle);

String sdPath = “…”; //any path

for (Iterator i = workbook.getWorksheets().iterator(); i.hasNext():wink: {
Worksheet sheet = i.next();
sheet.autoFitColumns();
sheet.autoFitRows();
}

//Saving the modified Excel file in default format
workbook.save(sdPath + “/output.xls”);
} catch (Exception ex) {
System.out.println(ex);
}

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Please download and use the latest version: Aspose.Cells
for Java v8.0.0.2
it should fix your issue.

We have tested your code with the latest version and it generated the correct output xls file. We have attached the output xls file for your reference.

Hi Shakeel,


I verified the output using new Aspose.cells 8.0.0.2 version, still no change in the result.

- cpunji

Hi cpunji,

Thanks for using Aspose.Cells.

Can you please highlight your issue in a screenshot because I do not see any noticeable difference in your output.xls file? It looks fine to me.

Attached are two files:

1. issue.png - Highlighted missing space, expected after performing auto-fit
2. withautofit.png - Highlighted space being introduced after using MS Excel autofit column

Thanks,
Cpunji

Hi,


Thanks for the screen shots.

I observed the issue as you mentioned by using your sample code as per your screen shots attached. It is not adjusting the width properly for the cells having font size set as bold etc. MS Excel does this ok. I have logged a ticket with an id “CELLSJAVA-40794” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,


Please try our latest version/fix: Aspose.Cells for Java v8.0.1.4 (attached).

We have fixed your issue now.

Let us know your feedback.

Thank you.

Thanks for the quick fix. It works as expected.


Thanks,
Cpunji

Hi,


Thanks for your feedback.

Good to know that your issue is resolved by the new fix/version. Feel free to contact us any time if you need further help or have some other issue or queries, we will glad to help you soon.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-40794) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.