Приём документов → реестр + журнал
Внесение данных из файлов приёма в реестр невостребованных документов и заполнение журнала. Дата внесения — текущая; журнал заполняется чисто (без строк-примеров шаблона). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
30
priem_register/readers/xlsx_reader.py
Normal file
30
priem_register/readers/xlsx_reader.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- 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
|
||||
Reference in New Issue
Block a user