Hi,
we have different results while converting an Excel file to pdf.
Case 1: We convert given Excel file “Test.xlsx” to pdf using given source code
Result: The multiline text in row 29 and 30 of Excel file is not shown completely in generated pdf. The first line is shown only. Not ok.
Case 2: Open Excel file in Excel and simply save it. Afterwards convert given Excel file “Test.xlsx” to pdf again
Result: The multiline text in row 29 and 30 of Excel file is now shown completely in generated pdf. That is the expected result.
Is there any way to achieve the result of case 2
Given row height of Excle file should be used in generated pdf - there should be no modification of row height
Btw saving excel file per Aspose before pdf conversion does not change the result of the pdf conversion.
I tested your scenario/case using your template Excel file. I found there are some rows in your Excel file whose height is auto (which means MS Excel will auto-fit those rows to wrap text/data into the cells when opening the Excel file into it to display the contents fully). In Aspose.Cells, we do provide Worksheet.autoFitRows(true) API, setting “true” would auto-fit those rows only whose height are auto. Please try to add a couple of lines to your sample code, I tested using it and it works as expected:
e.g. Sample code:
Workbook workbook = new Workbook("f:\\files\\Test.xlsx");
//Auto-fit rows in the worksheet which are set as "automatic".
Worksheet worksheet = workbook.getWorksheets().get("Typ A");
worksheet.autoFitRows(true);
com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
pdfSaveOptions.setPrintingPageType(PrintingPageType.IGNORE_BLANK);
pdfSaveOptions.setCompliance(PdfCompliance.NONE);
workbook.save("f:\\files\\out1.pdf", pdfSaveOptions);
Good to know that your issue has been resolved by using the suggested line of code. Feel free to reach out to us if you have any further queries or comments, and we will be happy to assist you soon.