https://github.com/rzh0001/Excel2SQL
generate insert sql from excel file
https://github.com/rzh0001/Excel2SQL
Last synced: 6 months ago
JSON representation
generate insert sql from excel file
- Host: GitHub
- URL: https://github.com/rzh0001/Excel2SQL
- Owner: rzh0001
- License: mit
- Created: 2017-01-12T09:02:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-20T14:15:34.000Z (over 5 years ago)
- Last Synced: 2024-08-13T07:08:25.734Z (10 months ago)
- Language: Python
- Size: 91.8 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - rzh0001/Excel2SQL - generate insert sql from excel file (Python)
README
# Excel2SQL
This script will generate insert sql accroding to the config and data in the excel file## Requirements
+ Python
+ xlrd (`pip install xlrd`)## Usage
> python excel2SQL.py excel\_file sheet\_indexargs| description
----|----
excel_file| if excel file and excel2SQL.py are in the same directory excel file path, it can be excel file name, otherwise it should be absolute path
sheet_index| excel worksheet index## Excel config

Line 1: TABLE\_NAME
Line 2: COLUMN\_NAME
Line 3: COLUMN\_TYPEtype | value | result in sql
----|---- | ----
string| grettygirl| values ('grettygirl')
int | 28 | values (28)
float | 12.1 | values (12.1)
function | fn\_get\_data\_id | select fn\_get\_data\_id from dualLine 4: data
## Example
1. COLUMN_TYPE config contain 'function'
```
INSERT TB_USER (USER_ID, NAME, AGE, EMAIL, ADDRESS, SCORE, BIRTHDAY, DATA_ID )
SELECT 'golden_three_fat', '金三胖', 28, '[email protected]', 'Nanjing', 12.1, '19900416', fn_get_data_id FROM DUAL;
```
2. COLUMN_TYPE config do not contain 'function'
```
INSERT TB_USER (USER_ID, NAME, AGE, EMAIL, ADDRESS, SCORE, BIRTHDAY )
VALUES ('golden_three_fat', '金三胖', 28, '[email protected]', 'Nanjing', 12.1, '19900416' );
```