我最近尝试将Excel升级为PDF脚本。到目前为止,我已经成功地将两个单独的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", configuration=config, 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文件并将2个文件合并在一起的工作,它工作得非常好。然而,我仍然在尝试无缝地将Excel图形导入PDF。有办法解决我的困境吗?目前正在使用的pdfkit和熊猫的替代品非常受欢迎
目前没有回答
相关问题 更多 >
编程相关推荐