This script converts CSV files to Excel files with multiple sheets if the number of rows exceeds a specified limit.
- Python 3.x
- pandas
- xlsxwriter
-
Install the required Python packages:
pip install pandas xlsxwriter
-
Ensure your directory structure is similar to the following:
2022 File/ 2022 File.csv 2022 File.xlsx 2023 File/ 01 TO 06 - 2023 File.csv 01 TO 06 - 2023 File.xlsx 07 - 2023 File.csv 08 - 2023 File.csv 09 - 2023 File.csv 10 - 2023 File.csv 11 - 2023 File.csv 12 - 2023 File.csv 2024 File/ 01- 2024 File.csv 02 - 2024 File.csv 03- 2024 File.csv 04- 2024 File.csv 05- 2024 File.csv 06- 2024 File.csv 07- 2024 File.csv
-
Open a terminal and navigate to the directory containing
index.py. -
Run the script:
python index.py
-
The script will iterate through all CSV files in the specified directory and convert them to Excel files with multiple sheets if necessary.
-
You can change the directory path and the maximum number of rows per sheet by modifying the
directoryandmax_rows_per_sheetvariables inindex.py.directory = './' # Replace with your directory path max_rows_per_sheet = 500000 # Adjust as needed
The script will convert CSV files in the specified directory to Excel files. For example, 2022 File/2022 File.csv will be converted to 2022 File/2022 File.xlsx.
This project is licensed under the MIT License.