feat: Enhance Excel file copying with sheet properties preservation
This commit is contained in:
parent
62ced4486b
commit
506dd2d116
26
src/main.py
26
src/main.py
@ -118,6 +118,32 @@ def copy_excel_file(source_path, destination_path, passwords):
|
||||
dest_cell.protection = copy(cell.protection)
|
||||
dest_cell.alignment = copy(cell.alignment)
|
||||
|
||||
# Copy sheet properties
|
||||
# Freeze panes
|
||||
if source_sheet.freeze_panes:
|
||||
dest_sheet.freeze_panes = source_sheet.freeze_panes
|
||||
|
||||
# Column dimensions
|
||||
for col in source_sheet.column_dimensions:
|
||||
dest_sheet.column_dimensions[col] = copy(source_sheet.column_dimensions[col])
|
||||
|
||||
# Row dimensions
|
||||
for row in source_sheet.row_dimensions:
|
||||
dest_sheet.row_dimensions[row] = copy(source_sheet.row_dimensions[row])
|
||||
|
||||
# Sheet properties
|
||||
if hasattr(source_sheet, 'sheet_properties'):
|
||||
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)
|
||||
|
||||
# Merged cells
|
||||
if source_sheet.merged_cells:
|
||||
for merged_range in source_sheet.merged_cells:
|
||||
dest_sheet.merge_cells(str(merged_range))
|
||||
|
||||
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
|
||||
logging.debug(f"Destination directory ensured: {os.path.dirname(destination_path)}")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user