#!/usr/bin/env python3 # -*- coding: utf-8 -*- import pdfplumber import time from tqdm import tqdm import pandas as pd def get_balance_table(file): # 获取合并资产负债表内容 start = 0 ret=[] with pdfplumber.open(file) as pdf: for page in pdf.pages: try: text = page.extract_text() if '合并资产负债表' in text and '编制单位' in text: start = 1 if start: table = page.extract_table({ "vertical_strategy": "lines", "horizontal_strategy": "lines", "explicit_vertical_lines": [], "explicit_horizontal_lines": [], "snap_tolerance": 3, "join_tolerance": 3, "edge_min_length": 3, "min_words_vertical": 3, "min_words_horizontal": 1, "keep_blank_chars": False, "text_tolerance": 3, "text_x_tolerance": None, "text_y_tolerance": None, "intersection_tolerance": 1, "intersection_x_tolerance": None, "intersection_y_tolerance": None, }) ret.extend(table) if '负债和所有者权益总计' in text and '所有者权益合计' in text: break except Exception as e: print(e) return ret if __name__ == "__main__": start_time = time.time() print("time start:%s"%(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(start_time)))) data = get_balance_table("1.pdf") df = pd.DataFrame(data) df=df[df.iloc[:,0].notnull()] df.to_excel("1.xlsx") end_time = time.time() print("time end:%s"%(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(end_time)))) print("take: %s S"%(int(end_time-start_time)))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统