我有一張 excel 表,里面有多個表格。我的問題是從 url 讀取 excel 檔案,然后轉換并保存為 .pdf 格式。現在我使用 pandas 和 matplotlib 來解決我的問題。但現在我只能閱讀第一張紙。所以我的問題是如何閱讀多張紙任何關于此的指標都會有所幫助。
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
url = "https://exceltesting.xlsx"
df = pd.read_excel(url)
# df = pd.read_excel(url, sheet_name=['Technologies','Schedule'])
fig, ax = plt.subplots(figsize=(12, 4))
ax.axis('tight')
ax.axis('off')
the_table = ax.table(cellText=df.values, colLabels=df.columns, loc='center')
pp = PdfPages("1.pdf")
pp.savefig(fig, bbox_inches='tight')
pp.close()
uj5u.com熱心網友回復:
例如,嘗試df = pd.read_excel(url, sheet_name = 1)用于第二張紙:)
然后,您可以對作業表進行 for 回圈,以將它們生成為帶有相應作業表的 pdf :)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/495118.html
標籤:Python 熊猫 matplotlib
下一篇:如何在單個圖中創建子圖組
