FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python/excelToDatabase.py at master · javaTyrant/Python · GitHub
javaTyrant
Python
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Python
/
excelToDatabase.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (29 loc) · 836 Bytes
Breadcrumbs
Python
/
excelToDatabase.py
Copy path
File metadata and controls
32 lines (29 loc) · 836 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from
openpyxl
import
load_workbook
import
pymysql
config
=
{
'host'
:
'127.0.0.1'
,
'port'
:
3306
,
'user'
:
'root'
,
'password'
:
'root'
,
'charset'
:
'utf8mb4'
,
#'cursorclass': pymysql.cursors.DictCursor
}
conn
=
pymysql
.
connect
(
**
config
)
conn
.
autocommit
(
1
)
cursor
=
conn
.
cursor
()
name
=
'lyexcel'
cursor
.
execute
(
'create database if not exists %s'
%
name
)
conn
.
select_db
(
name
)
table_name
=
'info'
cursor
.
execute
(
'create table if not exists %s(id MEDIUMINT NOT NULL AUTO_INCREMENT,name varchar(30),tel varchar(30),primary key (id))'
%
table_name
)
wb2
=
load_workbook
(
'hpu.xlsx'
)
ws
=
wb2
.
get_sheet_names
()
for
row
in
wb2
:
print
(
"1"
)
for
cell
in
row
:
value1
=
(
cell
[
0
].
value
,
cell
[
4
].
value
)
cursor
.
execute
(
'insert into info (name,tel) values(%s,%s)'
,
value1
)
print
(
"overing..."
)
# for row in A:
# print(row)
#print (wb2.get_sheet_names())
Back
|
FazBrowse Home
|
New Git URL