功能介绍:
提取pdf文件中的表格数据到excel文件中
视频演示:
Python 将pdf表格转换为excel表格
界面:
轮子 | 文件大小 |
---|---|
处理pdf文件:pdfplumber 处理excel:openpyxl | ![]() |
核心code:
def extract_table(pdf_file):
fn = pdf_file[pdf_file.rfind('\\') + 1: -5]
wb = Workbook()
wb.remove(wb.worksheets[0])
with pdfplumber.open(pdf_file) as pdf:
index = 1
for page in pdf.pages:
tables = page.extract_tables()
for table in tables:
ws = wb.create_sheet(title=f'Page{index}')
for row in table:
ws.append(row)
index += 1
wb.save(f'{fn}.xlsx')