Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Sep 19, 2024 1:21 pm

We are having a problem converting the attached excel sheet to PDF. It appears the issue is related to the macro contained in the file. We have attempted to disable macros but it did not help. We are using Spire for Python (Spire.Xls==14.7.3).
Attachments
MS Excel Spreadsheet (2)-test.xls.zip
(17.24 KiB) Downloaded 143 times

emarsh_zontal
 
Posts: 10
Joined: Tue Jul 23, 2024 5:27 pm

Fri Sep 20, 2024 7:38 am

Hello,

Thank you for your inquiry.
Did you encounter any errors during the conversion process? I converted the Excel document using the following code, but no error occurred. I have attached my test results for your reference. If our testing scenarios are different, please provide your complete code and testing environment (e.g. Win10, 64 bit). Thank you in advance.
Code: Select all
workbook = Workbook()

workbook.LoadFromFile("MS Excel Spreadsheet (2)-test.xls")

# Set the worksheet to adapt to the page during conversion
workbook.ConverterSetting.SheetFitToPage = True

workbook.SaveToFile("Output/ExcelToPDF.pdf", FileFormat.PDF)
workbook.Dispose()

Sincerely,
Amin
E-iceblue support team
Attachments
ExcelToPDF.zip
(107.4 KiB) Downloaded 137 times
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Mon Sep 23, 2024 6:58 pm

Hi Amin,

can you try the following? We want to print all non-empty and visible sheets, not only the first one.

Thank you

Code: Select all
sheets = [
   s
   for s in workbook.Worksheets
   if not s.IsEmpty
   and s.Visibility.value == 0  # WorksheetVisibility.Visible
]

for sheet in sheets:
   sheet.PageSetup.LeftMargin = 0
   sheet.PageSetup.TopMargin = 0
   sheet.PageSetup.RightMargin = 0
   sheet.PageSetup.BottomMargin = 0
   sheet.PageSetup.CenterFooter = ""
   sheet.PageSetup.CenterHeader = ""
   sheet.PageSetup.LeftFooter = ""
   sheet.PageSetup.LeftHeader = ""
   sheet.PageSetup.RightFooter = ""
   sheet.PageSetup.RightHeader = ""
   sheet.PageSetup.IsPrintGridlines = True
   sheet_pdf_file = create_tempfile(".pdf")
   sheet.SaveToPdf(sheet_pdf_file)

wolfgang.colsman
 
Posts: 30
Joined: Mon Jan 15, 2024 2:14 pm

Mon Sep 23, 2024 8:19 pm

I refactored our code to hide the sheets we do not want to print and use workbook.SaveToFile(pdf_filename, XlsFileFormat.PDF).

This works, thank you

The issue seems to be in sheet.SaveToPdf(sheet_pdf_file). While we don't need it any more, it would probably be good to have that fixed anyway.

wolfgang.colsman
 
Posts: 30
Joined: Mon Jan 15, 2024 2:14 pm

Tue Sep 24, 2024 3:23 am

Hello,wolfgang.colsman

We're very pleased to hear that you have found a temporary solution. In addition, I have tested your Excel document and encountered the following error on my side. Anyway, this issue has been logged in our bug tracking system under the number SPIREXLS-5486. Our Dev team will investigate it further, once there is any update, we will let you know.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Fri Nov 01, 2024 3:12 am

Hello,

Thank you for your patience.
Glad to inform that we just released Spire.Xls.14.10.2 hotfix which fixes the bug of SPIREXLS-5486, welcome to download it from the following link and test it.
Our website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.XLS/14.10.2

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Fri Nov 01, 2024 10:56 am

Can we have this released to pypi please? pypi is still on 14.7.3
https://pypi.org/project/Spire.Xls/#history

Thank you.

wolfgang.colsman
 
Posts: 30
Joined: Mon Jan 15, 2024 2:14 pm

Mon Nov 04, 2024 9:33 am

Hello,

Sorry, this is my error notification. The Python version of the bug fix code is currently being tested and we will provide you with the fix version as soon as possible. Thank you for your patience.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.XLS