refactor: Improve sheet view settings copying with granular property handling

This commit is contained in:
Bobby Abellana (aider) 2025-02-13 14:44:55 -08:00
parent 506dd2d116
commit 02aafd193f

View File

@ -136,8 +136,36 @@ def copy_excel_file(source_path, destination_path, passwords):
dest_sheet.sheet_properties = copy(source_sheet.sheet_properties)
# Sheet view properties
if hasattr(source_sheet, 'sheet_view'):
dest_sheet.sheet_view = copy(source_sheet.sheet_view)
if hasattr(source_sheet, 'sheet_view') and hasattr(source_sheet.sheet_view, 'selection'):
dest_sheet.sheet_view.selection = copy(source_sheet.sheet_view.selection)
if hasattr(source_sheet.sheet_view, 'zoomScale'):
dest_sheet.sheet_view.zoomScale = source_sheet.sheet_view.zoomScale
if hasattr(source_sheet.sheet_view, 'zoomScaleNormal'):
dest_sheet.sheet_view.zoomScaleNormal = source_sheet.sheet_view.zoomScaleNormal
if hasattr(source_sheet.sheet_view, 'zoomScalePageLayoutView'):
dest_sheet.sheet_view.zoomScalePageLayoutView = source_sheet.sheet_view.zoomScalePageLayoutView
if hasattr(source_sheet.sheet_view, 'zoomScaleSheetLayoutView'):
dest_sheet.sheet_view.zoomScaleSheetLayoutView = source_sheet.sheet_view.zoomScaleSheetLayoutView
if hasattr(source_sheet.sheet_view, 'showGridLines'):
dest_sheet.sheet_view.showGridLines = source_sheet.sheet_view.showGridLines
if hasattr(source_sheet.sheet_view, 'showRowColHeaders'):
dest_sheet.sheet_view.showRowColHeaders = source_sheet.sheet_view.showRowColHeaders
if hasattr(source_sheet.sheet_view, 'rightToLeft'):
dest_sheet.sheet_view.rightToLeft = source_sheet.sheet_view.rightToLeft
if hasattr(source_sheet.sheet_view, 'tabSelected'):
dest_sheet.sheet_view.tabSelected = source_sheet.sheet_view.tabSelected
if hasattr(source_sheet.sheet_view, 'showOutlineSymbols'):
dest_sheet.sheet_view.showOutlineSymbols = source_sheet.sheet_view.showOutlineSymbols
if hasattr(source_sheet.sheet_view, 'defaultGridColor'):
dest_sheet.sheet_view.defaultGridColor = source_sheet.sheet_view.defaultGridColor
if hasattr(source_sheet.sheet_view, 'view'):
dest_sheet.sheet_view.view = source_sheet.sheet_view.view
if hasattr(source_sheet.sheet_view, 'topLeftCell'):
dest_sheet.sheet_view.topLeftCell = source_sheet.sheet_view.topLeftCell
if hasattr(source_sheet.sheet_view, 'colorId'):
dest_sheet.sheet_view.colorId = source_sheet.sheet_view.colorId
if hasattr(source_sheet.sheet_view, 'zoomToFit'):
dest_sheet.sheet_view.zoomToFit = source_sheet.sheet_view.zoomToFit
# Merged cells
if source_sheet.merged_cells: