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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rn-forge-data
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Excel and tabular data helpers for Python programming
5
5
  Author: Rohit Narayanan
6
6
  Author-email: Rohit Narayanan <rohit.nn@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-data"
3
- version = "0.1.4"
3
+ version = "0.1.5"
4
4
  description = "Excel and tabular data helpers for Python programming"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-data"
3
- version = "0.1.4"
3
+ version = "0.1.5"
4
4
  description = "Excel and tabular data helpers for Python programming"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
@@ -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
- cells: list[Any] = []
395
- for index, value in enumerate(row):
396
- cell = WriteOnlyCell(sheet, value=value)
397
- if index in by_index:
398
- cell.number_format = by_index[index]
399
- cells.append(cell)
400
- sheet.append(cells)
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