Create a PostgreSQL tables from Excel files with automatic data type detection based on Sheetjs cell format
test_files | ||
.gitignore | ||
index.js | ||
package-lock.json | ||
package.json | ||
README.md | ||
test.js |
Sheetjs to PostgreSQL Creating a Table Demo
Convert Excel sheets to PostgreSQL tables with correct data types.
This demo project serves as a refernce implementation for SheetJS + PostgreSQL integration. For more details, vist the SheetJS Documentation.
Features
- Automatic data type detection from Excel columns
- Support various data formats:
- Numbers (integer and floating-point)
- Dates
- Booleans
- Text
- Handles special number formats (scientific notations, high precision)
- Clean column names for PostgreSQL compatibility
Prerequisites
- Node.js
- PostgreSQL (16)
- Python 3.x
Installation
- Install Python dependencies:
pip install -r test_files/requirements.txt
- Install Node.js dependencies:
npm install i
Setup
- Generate test_files:
python3 test_files/gen_test_files.py
- Configure PostgreSQL connection in
test.js
const client = new Client({
host: 'localhost',
database: 'SheetJSPG',
user: 'postgres',
password: '7509'
});
Run
node test.js
Test Files
The test suite includes various Excel files testing different data scenarios:
number_formats.xlsx
: Various numeric formatsdate_formats.xlsx
: Date handlingspecial_values.xlsx
: Edge casesprecision.xlsx
: High-precision numbersstring_formats.xlsx
: Text handlingboolean_formats.xlsx
: Boolean values
Type Mapping
- Excel dates → PostgreSQL
date
- Booleans → PostgreSQL
boolean
- High-precision numbers → PostgreSQL
numeric
- Standard numbers → PostgreSQL
double precision
- Text/other → PostgreSQL
text