Generate Excel stage-2
This commit is contained in:
@ -416,11 +416,22 @@ class SumasenExcel:
|
|||||||
|
|
||||||
print(f"min_col, min_row, max_col, max_row = {target_min_col}, {target_min_row}, {target_max_col}, {target_max_row}")
|
print(f"min_col, min_row, max_col, max_row = {target_min_col}, {target_min_row}, {target_max_col}, {target_max_row}")
|
||||||
|
|
||||||
# 新しいシートを作成(必要な場合)
|
# Get template sheet name from ini file
|
||||||
if 'Sheet' not in self.workbook.sheetnames:
|
section_config = self.conf.get_section(self.section_list[0]) # 現在の処理中のセクション
|
||||||
self.current_sheet = self.workbook.create_sheet('Sheet')
|
template_sheet_name = section_config.get("template_sheet")
|
||||||
|
|
||||||
|
if not template_sheet_name:
|
||||||
|
raise ValueError("Template sheet name not found in configuration")
|
||||||
|
|
||||||
|
# Create new sheet with template name if it doesn't exist
|
||||||
|
if template_sheet_name not in self.workbook.sheetnames:
|
||||||
|
self.current_sheet = self.workbook.create_sheet(template_sheet_name)
|
||||||
else:
|
else:
|
||||||
self.current_sheet = self.workbook['Sheet']
|
self.current_sheet = self.workbook[template_sheet_name]
|
||||||
|
|
||||||
|
# Remove default sheet if it exists
|
||||||
|
if 'Sheet' in self.workbook.sheetnames:
|
||||||
|
del self.workbook['Sheet']
|
||||||
|
|
||||||
# Copy column widths
|
# Copy column widths
|
||||||
for col in range(orig_min_col, orig_max_col + 1):
|
for col in range(orig_min_col, orig_max_col + 1):
|
||||||
@ -429,6 +440,16 @@ class SumasenExcel:
|
|||||||
self.current_sheet.column_dimensions[col_letter].width = \
|
self.current_sheet.column_dimensions[col_letter].width = \
|
||||||
self.template_sheet.column_dimensions[col_letter].width
|
self.template_sheet.column_dimensions[col_letter].width
|
||||||
|
|
||||||
|
# Copy row heights
|
||||||
|
for row in range(orig_min_row, orig_max_row + 1):
|
||||||
|
target_row = row - orig_min_row + target_min_row
|
||||||
|
if row in self.template_sheet.row_dimensions:
|
||||||
|
source_height = self.template_sheet.row_dimensions[row].height
|
||||||
|
if source_height is not None:
|
||||||
|
if target_row not in self.current_sheet.row_dimensions:
|
||||||
|
self.current_sheet.row_dimensions[target_row] = openpyxl.worksheet.dimensions.RowDimension(target_row)
|
||||||
|
self.current_sheet.row_dimensions[target_row].height = source_height
|
||||||
|
|
||||||
# Copy merged cells
|
# Copy merged cells
|
||||||
for merged_range in self.template_sheet.merged_cells:
|
for merged_range in self.template_sheet.merged_cells:
|
||||||
min_col, min_row, max_col, max_row = range_boundaries(str(merged_range))
|
min_col, min_row, max_col, max_row = range_boundaries(str(merged_range))
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user