Install
openclaw skills install poocr-vatinvoice2excel使用 poocr 库识别发票并导出 Excel。当用户需要识别增值税发票、批量处理发票文件或提取发票信息到 Excel 时调用此技能。
openclaw skills install poocr-vatinvoice2excel这个技能使用 poocr 库(基于腾讯云 AI)实现增值税发票的 OCR 识别,并将识别结果保存为 Excel 文件。
pip install poocr
需要获取腾讯云 API 的 SecretId 和 SecretKey:
import poocr
# 单张发票识别并导出 Excel
poocr.ocr2excel.VatInvoiceOCR2Excel(
input_path='发票文件路径.pdf',
output_path='输出目录',
id='你的SecretId',
key='你的SecretKey'
)
# 批量识别文件夹中的发票
poocr.ocr2excel.VatInvoiceOCR2Excel(
input_path='发票文件夹路径',
output_path='输出目录',
id='你的SecretId',
key='你的SecretKey'
)
| 参数 | 类型 | 说明 |
|---|---|---|
| input_path | str | 发票文件路径或包含发票的文件夹路径 |
| output_path | str | 输出 Excel 文件的目录路径 |
| id | str | 腾讯云 API SecretId |
| key | str | 腾讯云 API SecretKey |
import poocr
import os
class InvoiceOCR:
def __init__(self, secret_id, secret_key):
self.SecretId = secret_id
self.SecretKey = secret_key
def recognize_invoice(self, input_path, output_path):
"""识别发票并导出 Excel"""
if not os.path.exists(input_path):
raise FileNotFoundError(f"文件不存在: {input_path}")
poocr.ocr2excel.VatInvoiceOCR2Excel(
input_path=input_path,
output_path=output_path,
id=self.SecretId,
key=self.SecretKey
)
print(f"发票识别完成,结果已保存到: {output_path}")
# 使用示例
if __name__ == "__main__":
ocr = InvoiceOCR(
secret_id="你的SecretId",
secret_key="你的SecretKey"
)
ocr.recognize_invoice(
input_path="../test_files/VatInvoiceOCR",
output_path="../test_files/VatInvoiceOCR"
)