python - Python将Excel图形导入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", 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 和 pandas 的替代品!
解决方案
推荐阅读
- reporting-services - SSRS - 如何根据分组列的单个类别过滤或隐藏可见性
- c# - 如何将 VBA long &HFFFFFFF0 转换为 uint 以在 C# 中使用?
- javascript - Not able to delete the text after using JavaScript Regex
- ios - 将 SKProduct 价格提取到 UICollectionView 单元格标签中
- oracle - Oracle ODT for VS2017 and VS2019
- r - 使用 data.table 和 for-loop 提高代码执行时间效率
- android - How to use “viewport-fit=cover” and “maximum-scale=1” without disabling zoom on Android
- reactjs - Create a typescript function returning react component class
- powerbi - Highlight high to low numbers in a row in PowerBI
- websocket - Sending async message from micronaut ServerWebSocket