A Node.js-based tool for generating Excel files from SQL query results.
- π Multi-Sheet Support: Save multiple SQL query results in separate sheets within one Excel file
- π¨ Template Style System: Pre-defined Excel styling templates for consistent design with 7 built-in styles
- π Multiple DB Connections: Use different database connections for each sheet
- π Variable System: Use variables in queries for dynamic query generation
- π Enhanced Dynamic Variables: Extract values from database in real-time with advanced processing
- π Query Reuse: Define common queries and reuse them across multiple sheets
- βοΈ Parameter Override: Override query definition parameters for each sheet with different values
- π Auto Table of Contents: Automatically generate table of contents sheet with hyperlinks
- π Aggregation Features: Automatic aggregation and display of counts by specified column values
- π¦ Query Limits: Row count limiting for large data processing
- π₯οΈ CLI Interface: Simple command-line tool execution
- πͺ Windows Batch Files: Interactive batch files for Windows users
- π XML/JSON Support: Flexible configuration file format support
- π― Sheet-specific Styling: Apply different styles to individual sheets
- π¦ Standalone Executable: Generate standalone .exe files for distribution without Node.js dependency
- π Multi-language Support: Korean and English release packages
- π§ Release Automation: Automated release package generation with proper documentation
- π Creation Timestamp: Display creation timestamp on each Excel sheet
- β° Custom DateTime Variables: Support for 22 timezones worldwide with custom format (
${DATE.UTC:YYYY-MM-DD},${DATE.KST:YYYYλ MMμ DDμΌ},${DATE.EST:YYYY-MM-DD HH:mm}, etc.) or use local time (${DATE:YYYY-MM-DD}) - π SQL Query Formatting: Preserve original SQL formatting with line breaks in Table of Contents
- π§ Input Validation: Automatic whitespace trimming for file path inputs
- Per-sheet export routing by extension
.xlsx/.xlsβ Generate a single Excel workbook (existing behavior).csvβ Generate per-sheet CSV files- All other extensions (e.g.,
.txt,.log,.data,.sql, etc.) β Generate per-sheet TXT files (tab-delimited)
- Directory and filename rules for per-sheet export
- Output directory:
<output_basename>_<ext>(no dot). Example:output="d:/temp/report.csv"βd:/temp/report_csv/ - Each sheet becomes a separate file named after the sheet's
originalName - No 31-character truncation for CSV/TXT (Excel-only limit). Filenames sanitized and capped at 100 chars
- Output directory:
- Format defaults
- CSV: comma, UTF-8 with BOM, headers, CRLF
- TXT: tab, UTF-8 with BOM, headers, CRLF
- Validation warning for sheet names > 31 chars; note about Excel truncation
- TOC: Added "Original Name" column; removed note tooltip
- Non-interactive CLI: Run tasks directly with
app.js --mode(no menu)- Modes:
validate,test,export,help - Works in both Node and packaged EXE
- Modes:
# Validate query definition node app.js --mode=validate --xml=./queries/sample-queries.xml # or JSON node app.js --mode=validate --query=./queries/sample-queries.json # Test DB connections node app.js --mode=test # Export Excel node app.js --mode=export --xml=./queries/sample-queries.xml # or JSON node app.js --mode=export --query=./queries/sample-queries.json # Help node app.js --mode=help
sql2excel.exe --mode=validate --xml=./queries/sample-queries.xml sql2excel.exe --mode=test sql2excel.exe --mode=export --xml=./queries/sample-queries.xml sql2excel.exe --mode=help
- Node.js 16.0 or higher
- SQL Server 2012 or higher
- Appropriate database permissions
- Windows 10 or higher (64-bit)
- SQL Server 2012 or higher
- Appropriate database permissions
- No Node.js installation required
# Clone or download the source code npm install # Build standalone executable (optional) npm run build
- Download the release package from the releases section
- Extract to your desired directory
- Run interactive menu:
- English: Run
run.bat - Korean: Run
μ€ννκΈ°.bat
- English: Run
- Or use
sql2excel-v{version}.exedirectly
Create config/dbinfo.json file:
{
"dbs": {
"sampleDB": {
"server": "localhost",
"port": 1433,
"database": "SampleDB",
"user": "sa",
"password": "yourpassword",
"options": {
"encrypt": false,
"trustServerCertificate": true
}
},
"erpDB": {
"server": "erp-server.com",
"port": 1433,
"database": "ERP_Database",
"user": "erp_user",
"password": "erp_password",
"options": {
"encrypt": true,
"trustServerCertificate": false
}
}
}
}The tool supports Korean and English through environment variables:
- English: Run
run.bat(automatically setsLANGUAGE=en) - Korean: Run
μ€ννκΈ°.bat(automatically setsLANGUAGE=kr)
- English: Run
run.bat - Korean: Run
μ€ννκΈ°.bat
π‘ Note: Language is controlled via the
LANGUAGEenvironment variable. Default is English (en).
# English version run.bat # Korean version μ€ννκΈ°.bat
# English version run.bat # Korean version μ€ννκΈ°.bat
The interactive menu provides:
- Validate Query Definition File - Check your XML/JSON files for errors
- Test Database Connection - Verify database connectivity
- Generate Excel File (XML File) - Export using XML query definitions
- Generate Excel File (JSON File) - Export using JSON query definitions
- Show Help - Display detailed help information
# Using XML query file node src/excel-cli.js export --xml ./queries/sample-queries.xml # Using JSON query file node src/excel-cli.js export --query ./queries/sample-queries.json # Execute with variables node src/excel-cli.js export --xml ./queries/sample-queries.xml --var "year=2024" --var "dept=IT" # Using template style node src/excel-cli.js export --xml ./queries/sample-queries.xml --style modern
# Using XML query file sql2excel.exe export --xml ./queries/sample-queries.xml # Using JSON query file sql2excel.exe export --query ./queries/sample-queries.json # Execute with variables sql2excel.exe export --xml ./queries/sample-queries.xml --var "year=2024" --var "dept=IT" # Using template style sql2excel.exe export --xml ./queries/sample-queries.xml --style modern
# Export to Excel npm run export -- --xml ./queries/sample-queries.xml # Validate configuration npm run validate -- --xml ./queries/sample-queries.xml # Test database connection npm run list-dbs # Build standalone executable npm run build # Create release package npm run release
# Development node src/excel-cli.js validate --xml ./queries/sample-queries.xml # Standalone sql2excel.exe validate --xml ./queries/sample-queries.xml
# Development node src/excel-cli.js list-dbs # Standalone sql2excel.exe list-dbs
# Development node src/excel-cli.js list-styles # Standalone sql2excel.exe list-styles
For detailed usage and advanced features, refer to the following documents:
- π User Manual - Complete usage guide
- π Version History - Version-specific changes
<queries> <excel db="sampleDB" output="output/SalesReport.xlsx"> <header> <font name="Arial" size="12" color="FFFFFF" bold="true"/> <fill color="4F81BD"/> </header> </excel> <!-- Regular variables --> <vars> <var name="startDate">2024εΉ΄01ζ01ζ₯</var> <var name="endDate">2024εΉ΄12ζ31ζ₯</var> </vars> <!-- Dynamic variables --> <dynamicVars> <dynamicVar name="activeCustomers" description="Active customer list"> <![CDATA[ SELECT CustomerID, CustomerName, Region FROM Customers WHERE IsActive = 1 ]]> </dynamicVar> </dynamicVars> <sheet name="MonthlySales" use="true" aggregateColumn="Month"> <![CDATA[ SELECT MONTH(OrderDate) as Month, SUM(TotalAmount) as Sales FROM Orders WHERE YEAR(OrderDate) = 2024 AND CustomerID IN (${activeCustomers.CustomerID}) GROUP BY MONTH(OrderDate) ]]> </sheet> </queries>
node src/excel-cli.js export --xml ./queries/sales-report.xml \ --var "startDate=2024εΉ΄01ζ01ζ₯" \ --var "endDate=2024εΉ΄06ζ30ζ₯"
The tool supports dynamic variables that can extract data at runtime and use it in queries:
| Type | Description | Access Pattern | Default |
|---|---|---|---|
column_identified |
Extract all columns as arrays keyed by column name | ${varName.columnName} |
β Yes |
key_value_pairs |
Extract first two columns as key-value pairs | ${varName.key} |
No |
<!-- Using column_identified (default) --> <dynamicVar name="customerData" description="Customer information"> <![CDATA[ SELECT CustomerID, CustomerName, Region FROM Customers ]]> <!-- type omitted - defaults to column_identified --> </dynamicVar> <!-- Using key_value_pairs --> <dynamicVar name="statusMapping" description="Status mapping"> <![CDATA[ SELECT StatusCode, StatusName FROM StatusCodes ]]> <type>key_value_pairs</type> </dynamicVar>
-- In your sheet queries SELECT * FROM Orders WHERE CustomerID IN (${customerData.CustomerID}) AND Status IN (${statusMapping.StatusCode})
- Node.js 16.0 or higher
- SQL Server 2012 or higher
- Appropriate database permissions
- Website: www.sql2excel.com
- Email: sql2excel.nodejs@gmail.com