convert excel to pdf in python

二次信任 提交于 2019-12-10 13:34:06

问题


Is there a good python module to convert .xls file to PDF?


回答1:


Try xtopdf.

Note that there are some limitations:

Only simple spreadsheets that have plain text content, such as strings, numbers and dates, are supported. Spreadsheets with formatted cells (bold, italic, right-justified, etc.) or embedded images are not supported, or the formatting and images may be lost in the PDF output. Support for this input format means that you can publish your spreadsheets as PDF.




回答2:


I know this is super old, but unoconv works. E.g., unoconv -f pdf your_excel.xls. Note its just calling open office to do the actual conversion.

http://dag.wieers.com/home-made/unoconv/




回答3:


FileFormat = 57... as an alternative to the fragile ExportAsFixedFormat...

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()


来源:https://stackoverflow.com/questions/2018932/convert-excel-to-pdf-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!