feat: Add chartsheet warnings for Excel file processing
This commit is contained in:
parent
02aafd193f
commit
f9b982dd02
@ -75,6 +75,7 @@ def copy_excel_file(source_path, destination_path, passwords):
|
|||||||
# Create new sheet in destination workbook
|
# Create new sheet in destination workbook
|
||||||
from openpyxl.chartsheet import Chartsheet
|
from openpyxl.chartsheet import Chartsheet
|
||||||
if isinstance(source_sheet, Chartsheet):
|
if isinstance(source_sheet, Chartsheet):
|
||||||
|
chartsheet_warning = f"Chartsheet detected in '{os.path.basename(source_path)}' on sheet '{sheet_name}'."
|
||||||
# For chartsheets, we need to create a worksheet instead
|
# For chartsheets, we need to create a worksheet instead
|
||||||
dest_sheet = dest_wb.create_sheet(title=sheet_name)
|
dest_sheet = dest_wb.create_sheet(title=sheet_name)
|
||||||
|
|
||||||
@ -180,6 +181,8 @@ def copy_excel_file(source_path, destination_path, passwords):
|
|||||||
dest_wb.close()
|
dest_wb.close()
|
||||||
source_wb.close()
|
source_wb.close()
|
||||||
|
|
||||||
|
return chartsheet_warning # Return the warning message if any chartsheets were found
|
||||||
|
|
||||||
def remove_all_protection_tags(docx_path, output_path):
|
def remove_all_protection_tags(docx_path, output_path):
|
||||||
logging.info(f"Processing Word document: {docx_path}")
|
logging.info(f"Processing Word document: {docx_path}")
|
||||||
with zipfile.ZipFile(docx_path, 'r') as zip_in:
|
with zipfile.ZipFile(docx_path, 'r') as zip_in:
|
||||||
|
|||||||
@ -371,7 +371,9 @@ if input_method == "Upload Files" and uploaded_files and st.button("Process File
|
|||||||
temp_output_path = f"{temp_input_path}_processed"
|
temp_output_path = f"{temp_input_path}_processed"
|
||||||
|
|
||||||
if file_type == "Excel":
|
if file_type == "Excel":
|
||||||
copy_excel_file(temp_input_path, temp_output_path, passwords)
|
chartsheet_warning = copy_excel_file(temp_input_path, temp_output_path, passwords)
|
||||||
|
if chartsheet_warning:
|
||||||
|
st.warning(f"⚠️ {chartsheet_warning} Please check the processed file against the original to ensure data was copied correctly.")
|
||||||
else: # Word
|
else: # Word
|
||||||
remove_all_protection_tags(temp_input_path, temp_output_path)
|
remove_all_protection_tags(temp_input_path, temp_output_path)
|
||||||
|
|
||||||
@ -455,7 +457,9 @@ elif input_method == "Select Directory" and source_dir and dest_dir and st.butto
|
|||||||
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
|
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
|
||||||
|
|
||||||
if file_type == "Excel":
|
if file_type == "Excel":
|
||||||
copy_excel_file(source_path, dest_path, passwords)
|
chartsheet_warning = copy_excel_file(source_path, dest_path, passwords)
|
||||||
|
if chartsheet_warning:
|
||||||
|
st.warning(f"⚠️ {chartsheet_warning} Please check the processed file against the original to ensure data was copied correctly.")
|
||||||
else: # Word
|
else: # Word
|
||||||
remove_all_protection_tags(source_path, dest_path)
|
remove_all_protection_tags(source_path, dest_path)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user