简体   繁体   English

在python中将xls表转换为pdf文件

[英]convert xls sheets to pdf files in python

I'm currently developping a script in python 3.6 under Redhat.我目前正在 Redhat 下用 python 3.6 开发脚本。 The purpose is to extract 2 sheets from an .xlsm file and convert them to PDF file using sheet names as filename.目的是从 .xlsm 文件中提取 2 张工作表,并使用工作表名称作为文件名将它们转换为 PDF 文件。

Question: I looked for a solution on Forums for a while but didn't find the solution.问题:我在论坛上寻找了一段时间的解决方案,但没有找到解决方案。 Isn't there a specific python module to do that simply?没有一个特定的python模块可以简单地做到这一点吗?

Thanks谢谢

Here's a quick example I've put together, it should be sufficient to get you started:这是我整理的一个简单示例,应该足以让您入门:

import pandas as pd
import pdfkit as pdf

xl = pd.ExcelFile("your_file_name.xlsx")
df = xl.parse("Sheet1")
df.to_html('test.html')
PdfFilename='pdfPrintOut.pdf'
pdf.from_file('test.html', PdfFilename)

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

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