Enable automatic text wrapping in BOM templates
This commit is contained in:
1 parent
9f95b24067
commit
8986ce1759
1 file changed
+7
-1
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.comments import Comment
|
||||
from openpyxl.styles import Font, PatternFill
|
||||
from openpyxl.styles import Alignment, Font, PatternFill
|
||||
from openpyxl.worksheet.datavalidation import DataValidation
|
||||
|
||||
from .errors import TaskCenterError
|
||||
@@ -51,6 +51,11 @@ def write_bom_template(path: Path, records=()) -> Path:
|
||||
sheet.append(BOM_HEADERS)
|
||||
for record in records:
|
||||
sheet.append(tuple(record.get(header, '') for header in BOM_HEADERS))
|
||||
wrapped = Alignment(wrap_text=True, vertical='top')
|
||||
for row in sheet.iter_rows():
|
||||
for cell in row:
|
||||
cell.alignment = wrapped
|
||||
# Leave row heights automatic so Excel can fit wrapped text after editing.
|
||||
for cell, help_text in zip(sheet[1], _HEADER_HELP):
|
||||
cell.font = Font(bold=True, color='FFFFFF')
|
||||
cell.fill = PatternFill('solid', fgColor='1D3557')
|
||||
@@ -64,6 +69,7 @@ def write_bom_template(path: Path, records=()) -> Path:
|
||||
for column, width in {'A': 30, 'B': 64, 'C': 22, 'D': 22, 'E': 28, 'F': 18, 'G': 14,
|
||||
'H': 28, 'I': 12, 'J': 24, 'K': 12}.items():
|
||||
sheet.column_dimensions[column].width = width
|
||||
sheet.column_dimensions[column].alignment = wrapped
|
||||
for column in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J'):
|
||||
sheet.column_dimensions[column].number_format = '@'
|
||||
path = Path(path)
|
||||
|
||||
Reference in new issue
Block a user