繁体   English   中英

Python将一个excel表拆分成多个pdf个文件

[英]Pythn split an excel sheet to multiple pdf files

我有一个 excel 工作表,我想使用 python 将其拆分为多个pdf文件。要保存到多个 excel 文件,我使用了如下代码,但不确定如何针对 pdf output 修改它

import pandas as pd
data_df = pd.read_excel('./data_1.xlsx')
grouped_df = data_df.groupby('columnA')

for data in grouped_df.displayName:
    grouped_df.get_group(data[0]).to_excel("./IO/Files/"+data[0]+".xlsx")

这可以使用 matplotlib 来完成:

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

data_df = pd.read_excel('./data_1.xlsx')
grouped_df = data_df.groupby('columnA')

for data in grouped_df.displayName:
    temp_df = grouped_df.get_group(data[0])
    temp_df.to_excel("./IO/Files/"+data[0]+".xlsx")
    
    fig, ax = plt.subplots(figsize=(12,4))
    ax.axis('tight')
    ax.axis('off')
    ax.table(cellText=tmp_df.values,colLabels=tmp_df.columns,loc='center')
    pp = PdfPages("./IO/Files/"+ data[0] + ".pdf")
    pp.savefig(fig, bbox_inches='tight')
    pp.close()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM