We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

When Save To workbook to PDF, some text beyond the cell border

When Save To workbook to PDF, some text beyond the cell border.

System.out.println(CellsHelper.getVersion());
Workbook wb = new Workbook("/a.xlsx");
wb.getWorksheets().get(0).autoFitRow(0);
wb.getWorksheets().get(0).getCells().get(“A1”).setValue(“X”);
wb.save("/a.pdf");

a.zip (73.5 KB)

@xhaixia,

Thanks for the template file and sample code.

It looks like an issue with missing fonts. Could you share the underlying fonts (.ttf files) used in the workbook, we will check it soon:
e.g
MS Mincho
PMingLiu
FangSong
etc.

I Change to simsun

Cell cell = wb.getWorksheets().get(0).getCells().get(“B1”);
Style style = cell.getStyle();
Font f = style.getFont();
f.setName(“SimSun”);
cell.setStyle(style);

simsun.ttc.zip (8.8 MB)

@xhaixia,

Thanks for the updated code segment and font file.

After an initial test, I am able to observe the issue as you mentioned by using his sample code with your template file. I found that when saving the workbook to PDF file format after performing auto-fit row operation, some text still left beyond the cell border. If we save to XLSX file format, it works ok though. I have logged a ticket with an id “CELLSJAVA-42819” for your issue. We will look into it soon.

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

@xhaixia,

We have evaluated your issue a bit. Using the following code:

Workbook wb = new Workbook("a.xlsx");
System.out.println("Default Font: " + wb.getDefaultStyle().getFont());

Worksheet sheet = wb.getWorksheets().get(0);
System.out.println("Cell B1 Font: " + sheet.getCells().getStyle().getFont());

sheet.autoFitRow(0);
System.out.println("Row 1 Height in pixels: " + sheet.getCells().getRowHeightPixel(0));

wb.save("out.xlsx");
wb.save("out.pdf");

You will find that the workbook’s default Font is “宋体”. It is a Chinese font. So please set default edit language of Microsoft Excel to “Chinese(PRC)” (see attachment “default_edit_language.png”). Then you can manually autofit Row 1 of the source file (“a.xlsx”) in Microsoft Excel, you can see the auofitted row height is 416 pixels (see attachment “Microsoft_Excel_autofit_row.png”) which is same as Aspose.Cells does. Then in the Microsoft Excel PrintPreview, you will see the text is also cut off (see attachment “Microsoft_Excel_printview.png”).
So this is not an issue.

In other words, when you autofit row in Microsoft Excel, it does not guarantee that the text will not be cut off in printview.
Note: Make sure that the font “宋体”(“SimSun”) is installed.

Microsoft_Excel_autofit_row.png (108.0 KB)
Microsoft_Excel_printview.png (141.8 KB)
default_edit_language.png (138.6 KB)