Generate Excel stage-2

This commit is contained in:
hayano
2024-11-06 09:17:30 +00:00
parent 139c0987bc
commit 768dd6e261
4 changed files with 44 additions and 22 deletions

Binary file not shown.

View File

@ -410,8 +410,11 @@ class SumasenExcel:
print(f"orig_rage={orig_range},target_range={target_range}")
# 範囲をパースする
min_col, min_row, max_col, max_row = range_boundaries(orig_range)
print(f"min_col, min_row, max_col, max_row = {min_col}, {min_row}, {max_col}, {max_row}")
orig_min_col, orig_min_row, orig_max_col, orig_max_row = range_boundaries(orig_range)
target_min_col, target_min_row, target_max_col, target_max_row = range_boundaries(target_range)
print(f"min_col, min_row, max_col, max_row = {orig_min_col}, {orig_min_row}, {orig_max_col}, {orig_max_row}")
print(f"min_col, min_row, max_col, max_row = {target_min_col}, {target_min_row}, {target_max_col}, {target_max_row}")
# 新しいシートを作成(必要な場合)
if 'Sheet' not in self.workbook.sheetnames:
@ -462,34 +465,53 @@ class SumasenExcel:
target_page_setup = self.current_sheet.page_setup
source_page_setup = self.template_sheet.page_setup
# Copy all page setup attributes
target_page_setup.paperSize = source_page_setup.paperSize
target_page_setup.orientation = source_page_setup.orientation
target_page_setup.fitToHeight = source_page_setup.fitToHeight
target_page_setup.fitToWidth = source_page_setup.fitToWidth
target_page_setup.zoom = source_page_setup.zoom
target_page_setup.scale = source_page_setup.scale
# Copy supported page setup attributes
copyable_attrs = [
'paperSize',
'orientation',
'fitToHeight',
'fitToWidth',
'scale'
]
for attr in copyable_attrs:
try:
if hasattr(source_page_setup, attr):
setattr(target_page_setup, attr, getattr(source_page_setup, attr))
except Exception as e:
logging.warning(f"Could not copy page setup attribute {attr}: {str(e)}")
# Copy margins
target_margins = self.current_sheet.page_margins
source_margins = self.template_sheet.page_margins
target_margins.left = source_margins.left
target_margins.right = source_margins.right
target_margins.top = source_margins.top
target_margins.bottom = source_margins.bottom
target_margins.header = source_margins.header
target_margins.footer = source_margins.footer
margin_attrs = ['left', 'right', 'top', 'bottom', 'header', 'footer']
for attr in margin_attrs:
try:
if hasattr(source_margins, attr):
setattr(target_margins, attr, getattr(source_margins, attr))
except Exception as e:
logging.warning(f"Could not copy margin attribute {attr}: {str(e)}")
# Copy print options
target_print = self.current_sheet.print_options
source_print = self.template_sheet.print_options
target_print.horizontalCentered = source_print.horizontalCentered
target_print.verticalCentered = source_print.verticalCentered
target_print.gridLines = source_print.gridLines
target_print.gridLinesSet = source_print.gridLinesSet
print_attrs = [
'horizontalCentered',
'verticalCentered',
'gridLines',
'gridLinesSet'
]
for attr in print_attrs:
try:
if hasattr(source_print, attr):
setattr(target_print, attr, getattr(source_print, attr))
except Exception as e:
logging.warning(f"Could not copy print option {attr}: {str(e)}")
return {"status": True, "message": "Successfully copied template range"}
except Exception as e: