c
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
import pandas as pdc
|
||||
from openpyxl import load_workbook
|
||||
|
||||
input_folder = r"d:\input"
|
||||
|
||||
merged_dfs = []
|
||||
total_rows = 0
|
||||
|
||||
excel_files = [f for f in os.listdir(input_folder) if f.endswith(".xlsx")]
|
||||
|
||||
for excel_file in sorted(excel_files):
|
||||
try:
|
||||
wb = load_workbook(excel_file, data_only=False)
|
||||
sheet_name = wb.sheetnames[0] # Get first sheet name
|
||||
df = pdc.read_excel(excel_file, sheet_name=sheet_name)
|
||||
merged_dfs.append(df)
|
||||
total_rows += len(df)
|
||||
except Exception as e:
|
||||
print(f"Error processing {excel_file}: " + str(e))
|
||||
continue
|
||||
|
||||
if merged_dfs:
|
||||
merged_output = pd.concat(merged_dfs, ignore_index=True)
|
||||
output_file = r"d:\output\merged_file.xlsx"
|
||||
merged_output.to_excel(output_file, index=False)
|
||||
print(f"Successfully saved {total_rows} rows to output file")
|
||||
Reference in New Issue
Block a user