fix: обходной путь для xlsx с битыми стилями (сметные программы)

Файлы из Гранд-Сметы и других сметных ПО содержат нестандартные
стили заливки, которые ломают openpyxl (TypeError: expected Fill).
Добавлен XML-парсинг через zipfile+ElementTree как fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-25 17:46:30 +10:00
co-authored by Claude Opus 4.6
parent b74384acb7
commit 357e316854
+16
View File
@@ -98,6 +98,22 @@ else:
## Как работать с файлами пользователя
- Файлы пользователя лежат в /data (текущая рабочая директория)
- Для Excel — openpyxl или pandas
- ⚠️ Если openpyxl выдаёт ошибку стилей (TypeError: expected Fill/Font/etc) — файл из сметной программы с нестандартными стилями. Используй XML-парсинг:
```python
import zipfile, xml.etree.ElementTree as ET
z = zipfile.ZipFile('файл.xlsx')
ns = {'s': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'}
ss = ET.parse(z.open('xl/sharedStrings.xml')).getroot()
strings = [''.join(t.text or '' for t in si.findall('.//s:t', ns)) for si in ss.findall('.//s:si', ns)]
sheet = ET.parse(z.open('xl/worksheets/sheet1.xml')).getroot()
for row in sheet.findall('.//s:row', ns):
for c in row.findall('s:c', ns):
v = c.find('s:v', ns)
val = v.text if v is not None else ''
if c.get('t') == 's' and val.isdigit(): val = strings[int(val)]
print(f"{c.get('r')}={val}", end=' ')
print()
```
- Для Word — python-docx
- Для PDF — pymupdf (fitz)
- ВСЕГДА показывай результат: первые строки, итоги