Generate Excel stage-2
This commit is contained in:
BIN
SumasenLibs/excel_lib/sumaexcel/.sumaexcel.py.swp
Normal file
BIN
SumasenLibs/excel_lib/sumaexcel/.sumaexcel.py.swp
Normal file
Binary file not shown.
@ -410,8 +410,11 @@ class SumasenExcel:
|
|||||||
print(f"orig_rage={orig_range},target_range={target_range}")
|
print(f"orig_rage={orig_range},target_range={target_range}")
|
||||||
|
|
||||||
# 範囲をパースする
|
# 範囲をパースする
|
||||||
min_col, min_row, max_col, max_row = range_boundaries(orig_range)
|
orig_min_col, orig_min_row, orig_max_col, orig_max_row = range_boundaries(orig_range)
|
||||||
print(f"min_col, min_row, max_col, max_row = {min_col}, {min_row}, {max_col}, {max_row}")
|
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:
|
if 'Sheet' not in self.workbook.sheetnames:
|
||||||
@ -462,34 +465,53 @@ class SumasenExcel:
|
|||||||
target_page_setup = self.current_sheet.page_setup
|
target_page_setup = self.current_sheet.page_setup
|
||||||
source_page_setup = self.template_sheet.page_setup
|
source_page_setup = self.template_sheet.page_setup
|
||||||
|
|
||||||
# Copy all page setup attributes
|
# Copy supported page setup attributes
|
||||||
target_page_setup.paperSize = source_page_setup.paperSize
|
copyable_attrs = [
|
||||||
target_page_setup.orientation = source_page_setup.orientation
|
'paperSize',
|
||||||
target_page_setup.fitToHeight = source_page_setup.fitToHeight
|
'orientation',
|
||||||
target_page_setup.fitToWidth = source_page_setup.fitToWidth
|
'fitToHeight',
|
||||||
target_page_setup.zoom = source_page_setup.zoom
|
'fitToWidth',
|
||||||
target_page_setup.scale = source_page_setup.scale
|
'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
|
# Copy margins
|
||||||
target_margins = self.current_sheet.page_margins
|
target_margins = self.current_sheet.page_margins
|
||||||
source_margins = self.template_sheet.page_margins
|
source_margins = self.template_sheet.page_margins
|
||||||
|
|
||||||
target_margins.left = source_margins.left
|
margin_attrs = ['left', 'right', 'top', 'bottom', 'header', 'footer']
|
||||||
target_margins.right = source_margins.right
|
for attr in margin_attrs:
|
||||||
target_margins.top = source_margins.top
|
try:
|
||||||
target_margins.bottom = source_margins.bottom
|
if hasattr(source_margins, attr):
|
||||||
target_margins.header = source_margins.header
|
setattr(target_margins, attr, getattr(source_margins, attr))
|
||||||
target_margins.footer = source_margins.footer
|
except Exception as e:
|
||||||
|
logging.warning(f"Could not copy margin attribute {attr}: {str(e)}")
|
||||||
|
|
||||||
# Copy print options
|
# Copy print options
|
||||||
target_print = self.current_sheet.print_options
|
target_print = self.current_sheet.print_options
|
||||||
source_print = self.template_sheet.print_options
|
source_print = self.template_sheet.print_options
|
||||||
|
|
||||||
target_print.horizontalCentered = source_print.horizontalCentered
|
print_attrs = [
|
||||||
target_print.verticalCentered = source_print.verticalCentered
|
'horizontalCentered',
|
||||||
target_print.gridLines = source_print.gridLines
|
'verticalCentered',
|
||||||
target_print.gridLinesSet = source_print.gridLinesSet
|
'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"}
|
return {"status": True, "message": "Successfully copied template range"}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
BIN
SumasenLibs/excel_lib/testdata/certificate_5033.xlsx
vendored
BIN
SumasenLibs/excel_lib/testdata/certificate_5033.xlsx
vendored
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user