https://github.com/fanmolh/excel_db
excel文件导入数据库中
https://github.com/fanmolh/excel_db
excel python
Last synced: 4 months ago
JSON representation
excel文件导入数据库中
- Host: GitHub
- URL: https://github.com/fanmolh/excel_db
- Owner: fanmolh
- Created: 2019-01-11T09:22:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T20:55:00.000Z (over 1 year ago)
- Last Synced: 2024-03-15T02:14:03.395Z (about 1 year ago)
- Topics: excel, python
- Language: Python
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - fanmolh/excel_db - excel文件导入数据库中 (Python)
README
# excel_db
excel文件导入数据库中
========================
```python
def run(table_name,url,excel_file,config)
"""
:param table_name:
需要导入的表名
:param url:
数据库url 例如:"mysql+pymysql://root:[email protected]:3306/dbname"
:param excel_file:
excel文件的全路径
:param config:
键为sheet name
值为当前sheet的导入规则
键:
mt_id .....
pkcs 数据库中表的某字段名(一个或多个)作为判断唯一性的标准,使其导入不存在的数据。
col_map:
键为excel列名
值为数据库字段名
add_rs:填充列
键为表字段名
值为当前字段下需要填充的值"""
```
实例:
-------
```python
from excel_db.run import run
config = {
'HMC':
{
'mt_id': '30',
'pkcs': ['ip'],
'col_map':
{
'SN': 'sn',
'IP': 'ip',
'ACCOUNT': 'account',
'PASSWD': 'password',
'LOCATION': 'location'
},
'add_rs': {'mt_id': '30', 'available_flag': '1', 'platform': 'HMC'}
}
}
run("t_ip_info","mysql+pymysql://root:[email protected]:3306/dbname","tmp.xlsx",config)
```