rn-forge-data 0.1.4__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/PKG-INFO +1 -1
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/pyproject.toml +1 -1
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/pyproject.toml.orig +1 -1
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/src/rn_forge/data/excel.py +17 -7
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/LICENSE +0 -0
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/README.md +0 -0
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/src/rn_forge/data/__init__.py +0 -0
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/src/rn_forge/data/pandas.py +0 -0
- {rn_forge_data-0.1.4 → rn_forge_data-0.1.5}/src/rn_forge/data/py.typed +0 -0
|
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, cast
|
|
|
11
11
|
import openpyxl
|
|
12
12
|
from openpyxl.cell import WriteOnlyCell
|
|
13
13
|
from openpyxl.styles import Alignment, Border, Font, PatternFill, Protection
|
|
14
|
+
from openpyxl.utils import get_column_letter
|
|
14
15
|
from openpyxl.workbook.workbook import Workbook
|
|
15
16
|
from openpyxl.worksheet.worksheet import Worksheet
|
|
16
17
|
from rn_forge.commons.lang.dataclasses import DataclassMixin
|
|
@@ -388,16 +389,25 @@ def write_xlsx(
|
|
|
388
389
|
|
|
389
390
|
workbook = openpyxl.Workbook(write_only=True)
|
|
390
391
|
sheet = workbook.create_sheet(sheet_title)
|
|
392
|
+
width = len(headers) or dataset.width
|
|
393
|
+
dimension = (
|
|
394
|
+
f"A1:{get_column_letter(max(width, 1))}{max(len(dataset) + bool(headers), 1)}"
|
|
395
|
+
)
|
|
396
|
+
# A write-only sheet has no dimension, so a read-only loader scans the sheet
|
|
397
|
+
# twice to find one; declaring it up front avoids the second scan.
|
|
398
|
+
sheet.calculate_dimension = lambda: dimension # openpyxl reads this hook by name
|
|
391
399
|
if headers:
|
|
392
400
|
sheet.append(headers)
|
|
393
401
|
for row in cast("Any", dataset): # tablib is untyped
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
cell.number_format =
|
|
399
|
-
|
|
400
|
-
|
|
402
|
+
if by_index:
|
|
403
|
+
cells: list[Any] = list(row)
|
|
404
|
+
for index, fmt in by_index.items():
|
|
405
|
+
cell = WriteOnlyCell(sheet, value=cells[index])
|
|
406
|
+
cell.number_format = fmt
|
|
407
|
+
cells[index] = cell
|
|
408
|
+
sheet.append(cells)
|
|
409
|
+
else:
|
|
410
|
+
sheet.append(row)
|
|
401
411
|
return ExcelUtils.write_workbook_bytes(workbook).getvalue()
|
|
402
412
|
|
|
403
413
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|