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
- π File Validation: Automatic filename validation and Korean character warnings
- π― 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
- β° Enhanced DateTime Variables: 20+ automatic datetime variables for real-time timestamp generation
- π SQL Query Formatting: Preserve original SQL formatting with line breaks in Table of Contents
- π§ Input Validation: Automatic whitespace trimming for file path inputs
- 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
sql2excel.bat
for interactive menu - Or use
sql2excel-v{version}.exe
directly
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
}
}
}
}
Run the interactive batch file for a user-friendly menu:
sql2excel.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