.xlsx and xls(Latest Versions) to pdf using python

后端 未结 3 1083
一向
一向 2020-11-28 08:37

With the help of this .doc to pdf using python Link I am trying for excel (.xlsx and xls formats)

Following is modified Code for Excel:



        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 08:50

    I got the same thing and the same error... ANSWER: 57.... see below...

    from win32com import client
    import win32api
    
    def exceltopdf(doc):
        excel = client.DispatchEx("Excel.Application")
        excel.Visible = 0
    
        wb = excel.Workbooks.Open(doc)
        ws = wb.Worksheets[1]
    
        try:
            wb.SaveAs('c:\\targetfolder\\result.pdf', FileFormat=57)
        except Exception, e:
            print "Failed to convert"
            print str(e)
        finally:
            wb.Close()
            excel.Quit()
    

    ... as an alternative to the fragile ExportAsFixedFormat...

提交回复
热议问题