Skip to content

Commit 85a2771

Browse files
authored
Created README
1 parent 5741250 commit 85a2771

File tree

1 file changed

+119
-2
lines changed

1 file changed

+119
-2
lines changed

README.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,119 @@
1-
# Excel_to_SQL_Table-Mapped_TXT_Exporter
2-
Convert Excel (.xlsx) files to pipe-delimited TXT files, automatically mapping columns and order to an existing SQL Server table structure. Ideal for legacy system integration, automated data imports, and ETL pipelines.
1+
# Excel to SQL Table-Mapped TXT Exporter
2+
3+
Convert Excel (.xlsx) files into pipe-delimited TXT files, automatically mapping columns and order to the structure of an existing SQL Server table.
4+
This utility is designed for seamless integration with legacy systems, automated data imports, and ETL pipelines—especially when you need to generate TXT files compatible with classic ASP, Access, or other systems with fixed text-import requirements.
5+
6+
## Overview
7+
8+
Many organizations receive data in Excel format that must be imported into databases or legacy systems requiring a specific TXT structure.
9+
If you need to ensure that your exported TXT files match the schema of a SQL Server table (column names, order, and types), this project provides a robust, script-based solution that automates the mapping and conversion process.
10+
11+
## Key Features
12+
13+
- **Automatic SQL Schema Detection**: Reads column names, types, and order from an existing SQL Server table and exports them to a CSV file.
14+
- **Excel to TXT Conversion**: Converts one or more Excel files to pipe-delimited TXT files, matching the required schema exactly.
15+
- **Batch Processing**: Handles multiple Excel files in a folder automatically.
16+
- **Legacy Compatibility**: Output format is compatible with systems expecting "Access-style" TXT files (no header row, fixed column order, empty fields for missing columns).
17+
- **Easy Adaptation**: Suitable for data migration, ETL, and legacy system integration.
18+
19+
## Typical Use Cases
20+
21+
- **Legacy System Integration**: When you must deliver TXT files for import by classic ASP, Access, or mainframe systems that expect a rigid text format.
22+
- **Automated Data Imports**: For scenarios where you receive Excel files from third parties and must automate their import into a database.
23+
- **ETL Pipelines**: As a preprocessing step to standardize data before further processing.
24+
- **Format Normalization**: When you need to ensure Excel files from diverse sources conform to a master schema.
25+
26+
## Workflow
27+
28+
1. **Extract Table Structure from SQL Server**
29+
30+
Use `Export-SqlTableColumns.ps1` to connect to your SQL Server and export the schema of the desired table (columns, types, order) to a CSV file.
31+
This CSV acts as the "blueprint" for subsequent TXT exports.
32+
33+
2. **Convert Excel Files to TXT**
34+
35+
Place your Excel files in the same folder as the scripts.
36+
Use `ConvertExcelToAccessStyleTxt.ps1` to process each Excel file and generate a TXT file for each, formatted and ordered as required by the table schema from the CSV.
37+
38+
3. **Import TXT into Your System**
39+
40+
The resulting TXT files can now be imported into your legacy system, classic ASP, Access, or any process that expects this format.
41+
42+
## Step-by-Step Usage
43+
44+
### 1. Requirements
45+
46+
- Windows with PowerShell 5.0 or later
47+
- [ImportExcel PowerShell module](https://github.com/dfinke/ImportExcel) (install with `Install-Module -Name ImportExcel -Scope CurrentUser`)
48+
- Access to the target SQL Server
49+
- Set the appropriate PowerShell execution policy if needed (see below)
50+
51+
### 2. Extract SQL Table Schema
52+
53+
Run the following script and provide the requested SQL Server connection parameters and table name:
54+
55+
```powershell
56+
.\Export-SqlTableColumns.ps1
57+
```
58+
59+
This will generate a CSV file (e.g., `table_columns.csv`) containing the column definitions of your SQL table.
60+
61+
### 3. Prepare Excel Files
62+
63+
Copy all Excel files (.xlsx) you wish to convert into the same folder as the scripts and the CSV schema file.
64+
65+
### 4. Convert Excel to TXT
66+
67+
Run the conversion script:
68+
69+
```powershell
70+
.\ConvertExcelToAccessStyleTxt.ps1
71+
```
72+
73+
- The script will prompt for the worksheet name (press Enter for the first worksheet).
74+
- TXT files will be generated in the `output/` subfolder, with one TXT per Excel file.
75+
- Each TXT will have columns ordered and named according to the SQL schema, with missing fields left empty.
76+
77+
### 5. (Optional) Set Execution Policy
78+
79+
If you encounter permissions issues running PowerShell scripts, you can temporarily allow execution for the current process:
80+
81+
```powershell
82+
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
83+
```
84+
85+
## Example Folder Structure
86+
87+
```
88+
YourFolder/
89+
│ Export-SqlTableColumns.ps1
90+
│ ConvertExcelToAccessStyleTxt.ps1
91+
│ table_columns.csv
92+
│ Example1.xlsx
93+
│ Example2.xlsx
94+
95+
└───output/
96+
Example1.txt
97+
Example2.txt
98+
```
99+
100+
## Script Details
101+
102+
### Export-SqlTableColumns.ps1
103+
104+
- Prompts the user for SQL Server connection info and target table name.
105+
- Exports the table structure (column names, types, order) to CSV.
106+
- CSV is used as the mapping template for TXT export.
107+
108+
### ConvertExcelToAccessStyleTxt.ps1
109+
110+
- Prompts for worksheet name, reads all .xlsx files in the folder.
111+
- Uses the CSV to determine required columns and order.
112+
- Produces pipe-delimited TXT files in the output folder, with values aligned to the schema.
113+
114+
## Troubleshooting
115+
116+
- Ensure the [ImportExcel](https://github.com/dfinke/ImportExcel) module is installed before running the conversion script.
117+
- Column names in Excel must exactly match those in the SQL table (case-sensitive).
118+
- Any missing columns in Excel will result in empty fields in the TXT file.
119+
- If you receive "script not allowed to run" errors, use the execution policy command above.

0 commit comments

Comments
 (0)