如何解决Python 将 Excel Graph 导入 PDF 文件
我最近尝试将我的 Excel 升级为 PDF 脚本。到目前为止,我已经成功地将 2 个单独的 PDF 文件合并为一个,这很棒。但是,我在尝试从第二个 Excel 文件导入 Excel 图形时遇到了很多麻烦。以下是我的代码:
import pandas as pd
import pdfkit
import os,PyPDF2
from PyPDF2 import PdfFileMerger
config = pdfkit.configuration(wkhtmltopdf='C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe')
options = {
'page-size': 'A4','margin-top': '0.75in','margin-right': '0.75in','margin-bottom': '0.75in','margin-left': '0.75in','footer-right': "Page [page] of [toPage]",'footer-left': "This Document is CLASSIFIED"
}
df = pd.read_excel("ReportExcel.xlsx")#input
df = df.fillna(" ")
df.to_html("ReportHTML.html",index = False)#to html
pdfkit.from_file("ReportHTML.html","ReportPDF.pdf",configuration=config,options= options)#to pdf
df = pd.read_excel("testpie.xlsx")#input
df = df.fillna(" ")
df.to_html("testpie.html",index = False)#to html
pdfkit.from_file("testpie.html","testpie.pdf",options= options)#to pdf
pdfs = ['ReportPDF.pdf','testpie.pdf']
merger = PdfFileMerger()
for pdf in pdfs:
merger.append(pdf)
merger.write("Final_True_Report.pdf")
merger.close()
第一个 excel,ReportExcel.xlsx,基本上是报表的主体
第二个 excel,testpie.xlsx,包含 excel 图表
对于转换 2 个 PDF 文件并将这两个文件合并在一起的工作,它运行得非常好。但是,我仍然坚持尝试将 Excel 图形无缝导入 PDF。有没有办法解决我的困境?非常欢迎当前使用的 pdfkit 和 pandas 的替代品!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。