Внесение данных из файлов приёма в реестр невостребованных документов и заполнение журнала. Дата внесения — текущая; журнал заполняется чисто (без строк-примеров шаблона). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
31 lines
779 B
Python
31 lines
779 B
Python
# -*- coding: utf-8 -*-
|
|
"""Читатель .xlsx (openpyxl)."""
|
|
from __future__ import annotations
|
|
|
|
from typing import List
|
|
|
|
import openpyxl
|
|
|
|
from ..models import CellValue
|
|
from .base import SourceReader
|
|
|
|
|
|
class XlsxReader(SourceReader):
|
|
def _rows(self) -> List[List[CellValue]]:
|
|
wb = openpyxl.load_workbook(self.path, data_only=True, read_only=True)
|
|
try:
|
|
ws = wb.worksheets[0]
|
|
rows: List[List[CellValue]] = []
|
|
for row in ws.iter_rows(values_only=True):
|
|
rows.append([_norm(v) for v in row])
|
|
return rows
|
|
finally:
|
|
wb.close()
|
|
|
|
|
|
def _norm(value: CellValue) -> CellValue:
|
|
if isinstance(value, str):
|
|
value = value.strip()
|
|
return value or None
|
|
return value
|