remove pandas, use calamine + tabulate

This commit is contained in:
yeungadrian 2025-01-04 00:22:59 +00:00
parent b95312172f
commit bbacf89b53
3 changed files with 9 additions and 11 deletions

View file

@ -30,8 +30,8 @@ dependencies = [
"markdownify", "markdownify",
"numpy", "numpy",
"python-pptx", "python-pptx",
"pandas",
"python-calamine", "python-calamine",
"tabulate",
"pdfminer.six", "pdfminer.six",
"puremagic", "puremagic",
"pydub", "pydub",

View file

@ -22,10 +22,11 @@ from warnings import warn, resetwarnings, catch_warnings
import mammoth import mammoth
import markdownify import markdownify
import olefile import olefile
import pandas as pd
import pdfminer import pdfminer
import pdfminer.high_level import pdfminer.high_level
import pptx import pptx
from python_calamine import load_workbook
from tabulate import tabulate
# File-format detection # File-format detection
import puremagic import puremagic
@ -726,11 +727,14 @@ class ExcelConverter(HtmlConverter):
if extension.lower() not in [".xlsx", ".xls", ".xlsb", ".xlsm"]: if extension.lower() not in [".xlsx", ".xls", ".xlsb", ".xlsm"]:
return None return None
sheets = pd.read_excel(local_path, sheet_name=None, engine="calamine") workbook = load_workbook(local_path)
md_content = "" md_content = ""
for s in sheets: for s in workbook.sheet_names:
sheet = workbook.get_sheet_by_name(s)
# TODO: Add argument to allow filtering empty row / columns
tabular_data = sheet.to_python(skip_empty_area=False)
md_content += f"## {s}\n" md_content += f"## {s}\n"
html_content = sheets[s].to_html(index=False) html_content = tabulate(tabular_data, tablefmt="html")
md_content += self._convert(html_content).text_content.strip() + "\n\n" md_content += self._convert(html_content).text_content.strip() + "\n\n"
return DocumentConverterResult( return DocumentConverterResult(

View file

@ -54,12 +54,6 @@ XLSX_TEST_STRINGS = [
"affc7dad-52dc-4b98-9b5d-51e65d8a8ad0", "affc7dad-52dc-4b98-9b5d-51e65d8a8ad0",
] ]
XLS_TEST_STRINGS = [
"## 09060124-b5e7-4717-9d07-3c046eb",
"6ff4173b-42a5-4784-9b19-f49caff4d93d",
"affc7dad-52dc-4b98-9b5d-51e65d8a8ad0",
]
DOCX_TEST_STRINGS = [ DOCX_TEST_STRINGS = [
"314b0a30-5b04-470b-b9f7-eed2c2bec74a", "314b0a30-5b04-470b-b9f7-eed2c2bec74a",
"49e168b7-d2ae-407f-a055-2167576f39a1", "49e168b7-d2ae-407f-a055-2167576f39a1",