This script allows you to copy specific column values from one Excel sheet to another, based on matching identifier columns. It is designed to handle large datasets and provides feedback through progress bars and colored messages.
- Python 3.x
openpyxllibrary
To install the required packages, run:
pip install -r requirements.txtThe script can be executed via the command line with several arguments. Here is the general format:
python lut_excel_transferer.py -s <source_filename> -d <dest_filename> -si <source_identifiers> -di <dest_identifiers> -sc <source_columns_to_copy> -sp <dest_columns_to_paste> [-so <source_offset>] [-sl <source_limit>] [-o <output_filename>] [-od <output_dir>]Before running the script, place the Excel files in the same folder as lut_excel_transferer.py. If you do not want to specify the file names in the parameters, rename the files as follows:
- Source file:
source.xlsx - Destination file:
dest.xlsx
- The source and destination files must have a header row.
- Matching columns must be provided in the same order for both source and destination files.
- The script provides real-time progress updates and uses colored messages to indicate success, warnings, and errors.
-sor--source-filename: The source Excel file (default is source.xlsx).-dor--dest-filename: The destination Excel file (default is dest.xlsx).-sior--source-to-match-identifiers: List of column titles to match in the source sheet.-dior--dest-to-match-identifiers: List of column titles to match in the destination sheet, in the same order as the source identifiers.-scor--source-to-copy-identifiers: List of column titles from the source sheet to copy.-spor--dest-to-paste-identifiers: List of column titles from the destination sheet to paste values, in the same order as the source identifiers.
-soor--source-offset: The number of rows to skip from the start of the source sheet (default is 0).-slor--source-limit: The number of rows to process from the source sheet (default is None, meaning all rows).-oor--output-filename: The name of the output file (default is output.xlsx).-odor--output-dir: The directory to save the output file (default is Output).-debor--debug: Enable debug messages for more detailed logging.
To transfer values from one Excel file to another where specific columns match:
python lut_excel_transferer.py -s 'source.xlsx' -d 'dest.xlsx' -si 'Date' 'Number' -di 'Date_Num' 'Number_ID' -sc 'Code' -sp 'Code_ID' -sl 1000In this example:
- The script matches rows where the
DateandNumbercolumns insource.xlsxmatch theDate_NumandNumber_IDcolumns indest.xlsx. - It copies the values from the
Codecolumn in the source sheet to theCode_IDcolumn in the destination sheet. - Only the first 1000 rows of the source sheet are processed.
The results are saved in the Output directory (default) or any directory specified via --output-dir.