簡體   English   中英

如何使用python將excel表轉換為pdf?

[英]How to convert an excel sheet to a pdf using python?

我有一個要轉換為 Python 的 excel 表。 需要為上述查詢建議包或模塊的建議。

我嘗試過使用 PDFWriter。 我正在使用 Pandas 讀取我的 excel 文件並將該數據集輸入到 PDFwriter 以創建 pdf 文件。 輸出 pdf 似乎是空白的。

import pandas as pd
from pdfrw import PdfWriter

wb = pd.read_excel('excel file path')

wb=PdfWriter()

wb.write('result.pdf')

僅以 1kb 創建的 pdf 文件..

這里有幾點:

  1. 您正在第一行的變量 wb 中讀取 DataFrame 並在下一行覆蓋相同的變量。 從 Excel 工作表中讀取的值將丟失。
  2. 您必須使用 addpage() 函數將內容添加到您的頁面。

你也可以試試這個鏈接

import pandas as pd
import pdfkit
df = pd.read_excel("file.xlsx")#input
df.to_html("file.html")#to html
pdfkit.from_file("file.html", "file.pdf")#to pdf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM