fix: Pass original filename to copy_excel_file for accurate chartsheet warnings
This commit is contained in:
parent
5031f9a0e6
commit
56fe322900
11
src/main.py
11
src/main.py
@ -54,7 +54,7 @@ def load_workbook_with_possible_passwords(filepath, passwords, keep_vba=False, d
|
||||
|
||||
raise ValueError(f"None of the provided passwords worked for '{filepath}'")
|
||||
|
||||
def copy_excel_file(source_path, destination_path, passwords):
|
||||
def copy_excel_file(source_path, destination_path, passwords, original_filename=None):
|
||||
logging.info(f"Processing Excel file: {source_path}")
|
||||
is_xlsm = source_path.lower().endswith('.xlsm')
|
||||
source_wb = load_workbook_with_possible_passwords(
|
||||
@ -75,10 +75,11 @@ def copy_excel_file(source_path, destination_path, passwords):
|
||||
# Create new sheet in destination workbook
|
||||
from openpyxl.chartsheet import Chartsheet
|
||||
if isinstance(source_sheet, Chartsheet):
|
||||
original_filename = os.path.basename(source_path)
|
||||
if '_processed' in original_filename: # If it's a temp file, get original name
|
||||
original_filename = original_filename.split('_processed')[0]
|
||||
chartsheet_warning = f"Chartsheet detected in '{original_filename}' on sheet '{sheet_name}'."
|
||||
# Use original_filename if provided, otherwise use source_path
|
||||
display_filename = original_filename or os.path.basename(source_path)
|
||||
if '_processed' in display_filename: # If it's a temp file, get original name
|
||||
display_filename = display_filename.split('_processed')[0]
|
||||
chartsheet_warning = f"Chartsheet detected in '{display_filename}' on sheet '{sheet_name}'."
|
||||
# For chartsheets, we need to create a worksheet instead
|
||||
dest_sheet = dest_wb.create_sheet(title=sheet_name)
|
||||
|
||||
|
||||
@ -371,7 +371,8 @@ if input_method == "Upload Files" and uploaded_files and st.button("Process File
|
||||
temp_output_path = f"{temp_input_path}_processed"
|
||||
|
||||
if file_type == "Excel":
|
||||
chartsheet_warning = copy_excel_file(temp_input_path, temp_output_path, passwords)
|
||||
# Pass original filename to copy_excel_file
|
||||
chartsheet_warning = copy_excel_file(temp_input_path, temp_output_path, passwords, original_filename=uploaded_file.name)
|
||||
if chartsheet_warning:
|
||||
st.warning(f"⚠️ {chartsheet_warning} Please check the processed file against the original to ensure data was copied correctly.")
|
||||
else: # Word
|
||||
|
||||
Loading…
Reference in New Issue
Block a user