From 02aafd193ffe045a0884162d38814d9308d5c179 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Thu, 13 Feb 2025 14:44:55 -0800 Subject: [PATCH] refactor: Improve sheet view settings copying with granular property handling --- src/main.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 2d49f0d..72a99f2 100644 --- a/src/main.py +++ b/src/main.py @@ -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: