Configuration-driven data import from Excel and CSV files with field mapping, validation, and batch processing.
pip3 install openpyxl pyyamlpip3 install python-calamine (for .xls legacy format)yaml
# import_config.yaml
task_name: "人员信息导入"
source:
file_path: "data/source.xlsx"
sheet_name: "Sheet1"
header_row: 1
key_field: "身份证号"
target:
file_path: "output/result.xlsx"
sheet_name: "人员信息"
header_row: 2
data_start_row: 3
field_mappings:
- source: "姓名"
target: "员工姓名"
required: true
- source: "身份证号"
target: "身份证号码"
required: true
validate: "id_card"
- source: "部门"
target: "所属部门"
default: "待分配"
error_handling:
backup: true
bash
python3 scripts/excel_import.py import_config.yaml
python3 scripts/excel_import.py import_config.yaml --dry-run # preview only
ModeSource ConfigUse CaseSingle filesource.file_pathOne-to-one importDirectory batchsource.type: "directory"Process all files in a folderMulti-sourcesources: [...]Merge from multiple filesCSV.csv file_pathAuto-encoding detection (UTF-8/GBK/GB2312)Legacy .xls.xls file_pathRequires python-calamineAuto headerheader_row: "auto"Detect header in complex sheets
For full parameter docs, see data-mapping-guide.md.
key_field, update existing or append new rowsTransforms: strip, upper, lower, title, int, float, date
Validators: required, not_empty, id_card, phone, email, numeric, range, regex, length
For advanced usage, see advanced-features.md.
OptionDescription--dry-runPreview mode, no file writes--verboseDetailed per-record output--no-backupSkip target file backup
python3 scripts/excel_import.py <config.yaml> with --dry-run first--dry-run