Reputation: 305
I have few excel files which I want to convert to pdf preserving the format. I used the following code but it throws Attribut error:Excel.Application.Workbooks I am not able to understand what am I missing here. Please help
from win32com import client
xlApp = client.Dispatch("Excel.Application")
books = xlApp.Workbooks.Open('C:/Users/Desktop/Imp tasks/exceltocsv/*.xlsx')
ws = books.Worksheets[0]
ws.Visible = 1
ws.ExportAsFixedFormat(0, 'C:/Users/Desktop/Imp tasks/exceltocsv/*.pdf')
error is:
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: Excel.Application.Workbooks
Upvotes: 2
Views: 5758
Reputation: 390
When attributes on Excel.Application do not exist, it is usually because the Excel application is open (possibly hidden) and it is in a modal loop such as editing a cell or an open/save file dialog.
Upvotes: 5