简体   繁体   English

在python中将excel转换为pdf

[英]convert excel to pdf in python

有没有一个好的python模块将.xls文件转换为PDF?

I know this is super old, but unoconv works. 我知道这是超级老,但unoconv工作。 Eg, unoconv -f pdf your_excel.xls . 例如, unoconv -f pdf your_excel.xls Note its just calling open office to do the actual conversion. 请注意它只是调用开放式办公室来进行实际转换。

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

FileFormat = 57... as an alternative to the fragile ExportAsFixedFormat... FileFormat = 57 ...作为脆弱的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()

Try xtopdf . 试试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. 不支持带有格式化单元格(粗体,斜体,右对齐等)或嵌入图像的电子表格,或者格式和图像可能会在PDF输出中丢失。 Support for this input format means that you can publish your spreadsheets as PDF. 支持此输入格式意味着您可以将电子表格发布为PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM