将pdf文档中的表格转化为execl表的表格
一、案例
将pdf文档中的表格转化为execl表的表格,而且是pdf是什么样子,execl表的格式也是什么样子。
二、代码
import camelot
# Specify PDF file path
pdf_path = r'C:\' #输入PDF文档的地址
# Read PDF and extract tables
tables = camelot.read_pdf(pdf_path, flavor='stream', pages='all')
# Specify a different directory for the Excel file
excel_path = r'C:\' #输出execl表的地址
# Write tables to Excel file
for i, table in enumerate(tables):
table.to_excel(excel_path, sheet_name=f"Sheet_{i+1}", index=False)
print(f"Excel file generated: {excel_path}")
三、注意事项:
1、务必新增pdf文档的地址
2、务必新增execl表的地址
若有问题可私信我,欢迎关注,谢谢小主。
本文介绍了如何使用Python的Camelot库将PDF文档中的表格转换为Excel格式,提供了一个实际代码示例,并提醒了用户注意指定PDF和Excel文件路径的操作步骤。
172

被折叠的 条评论
为什么被折叠?



