Format Issue with Excel to PDF Conversion

Hi,
We are currently evaluating Aspose.cells for our project. Our requirement is to have the application output report both in excel and pdf.

We faced some formatting issues when using Aspose.Cells to export the generated excel file like this:
//Instantiate the Workbook object
Workbook workbook = new Workbook();
//Open an excel file
workbook.Open(“f:\test\Input.xls”);
//Save the document in Pdf format
workbook.Save(“f:\test\Output.pdf“, FileFormatType.Pdf);

Format issues:
1: The font in PDF report is smaller then the excel report, resulting more rows appeared in PDF per page then excel.
2. Column width for pdf seems to be smaller then excel some times, resulting the content of the cell to be wrapped at different character (see G2_AC_test.pdf page 4 first column).
3. Top border of the first row of table on a new pdf page, is thiner then the excel report (G2_AC_test.pdf page 2).
4. We are not able to find any options to control the PDF page number. Our requirement required us to restart the page number for each excel tab.

Attached are the sample report we generated with ASPOSE.cell. Do let us know if there are existing API we can use, or there will be any fixes going to realize by ASPOSE to solve these issues.

G2_AC_test.pdf
https://ibm.box.com/s/wp85uph4ieov9pdu8azeom4zlxwpjegm

G2_AC_test.xlsx
https://ibm.box.com/s/yxv175plm6msomnqp1xerp4adacom0kn

@xuyingken

Thanks for using Aspose APIs.

It seems, your issues are being caused by the reason that page sizes of Excel and Aspose.Cells do not match. We will look into it thoroughly and logged it in our database as follows.

  • CELLSNET-46170 - Format Issue with Excel to PDF Conversion

Once, we will have some news for you, we will update you in this topic.


Please also note, you are using very old version of Aspose.Cells, so we recommend you to use the most recent version because we fix issues only in most recent version.

You can download the most recent version from NuGet i.e.

NuGet Gallery | Aspose.Cells 20.6.0

Thanks for the fast response. We are in fact using Aspose.Cells 18.5.1.

@xuyingken

Thanks for using Aspose APIs.

Download Link:
G2_AC_test_Ms.pdf (472.4 KB)

The attachment G2_AC_test_Ms.pdf is generated by Excel 2016 on our side.

For your four questions:

1 - The font in PDF report is smaller than the Excel report, resulting more rows appeared in PDF per page than Excel.

We could not find the issue. (Please check the attached PDF).


2 - Column width for PDF seems to be smaller than Excel sometimes, resulting the content of the cell to be wrapped at different character (Please see G2_AC_test.pdf page 4 first column).

We could not find the issue. (Please check the attached PDF).


3 - Top border of the first row of table on a new PDF page, is thinner than the Excel report (G2_AC_test.pdf page 2).

We can see the issue in page 2 of our generated PDF file.


4 - We are not able to find any options to control the PDF page number. Our requirement required us to restart the page number for each Excel tab.

Please try the following code:

C#

Workbook wb = new Workbook(srcFile); 
Console.WriteLine(wb.DefaultStyle.Font); 

foreach (Worksheet sheet in wb.Worksheets) 
{ 
	sheet.PageSetup.FirstPageNumber = 1; 
} 

wb.Save("outFile.pdf");

Note:

If the you still find issues, please highlight them by adding comments inside the output PDF.

Hi,
Thanks for the quick response.
For issue 1 and 2, I made some highlights on the pdf you provided. You can compare the excel and pdf.
Number of lines in excel and pdf is different.

As for the page number, the page number is changed, but the total page number is not reset (Page 1 of N).
https://ibm.box.com/s/uzu63659iznywsu797mk1ovxei93810p

This is a photo of the print out comparison of excel and pdf
https://ibm.box.com/s/x43v4uoyqhjsh4vs4ipb6wvbm9ag9j6m

@xuyingken

Thanks for highlighting the issues with comments. We have recorded them in our database. We will evaluate them and once we will have some update or fix for you, we will let you know by posting in this topic.

@xuyingken

We need to clarify the following points to you.

1 - The file we shared “G2_AC_test_Ms.pdf” is generated by Microsoft Excel 2016, it is the expected result. The expected result should be Microsoft Excel generated PDF or the Print Preview in the Microsoft Excel, not the view where you can edit the cell value in Microsoft Excel.

2 - Please compare our generated PDF and Microsoft Excel generated PDF (e.g. “G2_AC_test_Ms.pdf” we shared), make some screenshots and highlight them if you find some issues.


For your post: "As for the page number, the page number is changed, but the total page number is not reset (Page 1 of N). "

There is no way to achieve your requirement in Microsoft Excel. You can save one sheet to PDF by hiding other sheets. Then save another sheet to PDF by the same way… At the end, you can combine all the generated PDF files to one PDF file using Aspose.PDF product.

Thanks for the reply. We have resolve the paging problem with a similar solution provided by you.

For issue 3, top border of the first row of table on a new PDF page, is thinner than the Excel report, is there any solution? It seems like your generated pdf do not have this issue. Is it because the library we used is evolution version?

@xuyingken

Thanks for using Aspose APIs.

We can reproduce the issue on our side. The repeat row title is row 3 to row 19. And row 19 is filled with white color. When the row 19 is repeated on page 2, the filled white color on row 19 overlaps the top border of first row on page 2. If you clear the fill color on the row 19 with the following code, the top border of first row on page 2 will be OK.

Please also check the output PDF generated with Aspose.Cells for .NET v18.6 using the following code for your reference.

Download Link:
OutputByCells-v18.6.Pdf (217.8 KB)

C#

Workbook wb = new Workbook("G2_AC_test.xlsx");

Console.WriteLine(wb.DefaultStyle.Font);

//Clear fill color of row 19 
Style style = wb.CreateStyle();
style.Pattern = BackgroundType.None;
StyleFlag styleFlag = new StyleFlag();
styleFlag.CellShading = true;

Row row = wb.Worksheets["tab1"].Cells.Rows[18];
row.ApplyStyle(style, styleFlag);

wb.Save("OutputByCells-v18.6.Pdf");