I am trying to write a simple program in Python that saves an excel file to a pdf. I am using code I found with a google search. I ran
pip install Spire.XLS-for-Python
and
pip install plum-dispatch==2.1.1
which was successful . This is the code which I copied wholesale from the internet, changing only the filenames:
from spire.xls import *
from spire.common import *
inputFile = "/Users/myname/Desktop/XYZ.xlsm"
outputFile = "/Users/myname/Library/Mobile Documents/com~apple~CloudDocs/Development/CellRangeToPDF.pdf"
#create a workbook
workbook = Workbook()
#load a excel document
workbook.LoadFromFile(inputFile)
workbook.ConverterSetting.SheetFitToPage = True
#convert to PDF file
workbook.SaveToFile(outputFile, FileFormat.pdf)
workbook.Dispose()
It produces the following error (I don't include the full traceback but can if needed of course):
AttributeError: 'NoneType' object has no attribute 'Workbook_Dispose'
I couldn't find a satisfying answer in any of the usual forums
I am using Python 3.11 and PyCharm 2023.2. I reinstalled both Python and PyCharm to no avail.
I am new at this and have limited Python coding experience so please bear with me
Any advice is extremely welcome
Change "workbook.SaveToFile(outputFile, FileFormat.pdf)" to "workbook.SaveToFile(outputFile, FileFormat.PDF)".