04/23 Fixed bugs

This commit is contained in:
2026-04-23 15:53:29 -04:00
parent eab4207e1f
commit 2ab0408cbe
5 changed files with 123 additions and 15 deletions
+16 -1
View File
@@ -851,17 +851,32 @@ def _read_doc(path: str) -> str:
def _read_excel(path: str) -> str:
"""
Extract text from an Excel file via openpyxl (read-only mode).
Iteration stops as soon as accumulated content exceeds MAX_CHARS_PER_FILE
to avoid loading the entire workbook into memory for very large files.
The AI layer will truncate to MAX_CHARS_PER_FILE anyway, so there is no
value in continuing past that point.
"""
MAX_CHARS_PER_FILE = 14_000 # mirror the constant in AiSummaryView._run_ai
try:
import openpyxl
wb = openpyxl.load_workbook(path, read_only=True, data_only=True)
lines = []
total_chars = 0
for sheet in wb.worksheets:
lines.append(f"[Sheet: {sheet.title}]")
header = f"[Sheet: {sheet.title}]"
lines.append(header)
total_chars += len(header) + 1
for row in sheet.iter_rows(values_only=True):
row_str = "\t".join(
str(v) if v is not None else "" for v in row)
if row_str.strip():
lines.append(row_str)
total_chars += len(row_str) + 1
if total_chars >= MAX_CHARS_PER_FILE:
lines.append("[... content truncated to fit token limit ...]")
return "\n".join(lines)
return "\n".join(lines)
except ImportError:
raise ImportError(