Skip to content

Instantly share code, notes, and snippets.

@nikdudaev
Created February 10, 2025 12:25
Show Gist options
  • Save nikdudaev/6b600236826ae7d90705c98bb77b1aca to your computer and use it in GitHub Desktop.
Save nikdudaev/6b600236826ae7d90705c98bb77b1aca to your computer and use it in GitHub Desktop.
import pandas as pd
import argparse
def excel_to_csv(excel_file, output_csv):
# Load the Excel file
xls = pd.ExcelFile(excel_file)
# Read all sheets into a list of DataFrames
df_list = [xls.parse(sheet_name) for sheet_name in xls.sheet_names]
# Concatenate all sheets into a single DataFrame
combined_df = pd.concat(df_list, ignore_index=True)
# Save to CSV
combined_df.to_csv(output_csv, index=False)
print(f"All sheets from {excel_file} have been merged and saved to {output_csv}")
def main():
parser = argparse.ArgumentParser(description="Merge all sheets of an Excel file into a single CSV file.")
parser.add_argument("input", help="Path to the input Excel file")
parser.add_argument("output", help="Path to the output CSV file")
args = parser.parse_args()
excel_to_csv(args.input, args.output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment