-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxls_to_sqlite.py
49 lines (33 loc) · 1020 Bytes
/
xls_to_sqlite.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#reading excel file <list.xls> and create database with it
import sqlite3
import xlrd
address="list.xls"
#address=input('Enter file path :')
tabel_list=[]
#connecting to excel sheet
excel_reader=xlrd.open_workbook(address)
sheet = excel_reader.sheet_by_index(0)
sheet.cell_value(0,0)
#fill a list of list with excel content
for i in range(2,sheet.nrows):
row=sheet.row_values(i)
tabel_list.append(row)
#created database with tabel
conn=sqlite3.connect("DataBase")
curser=conn.cursor()
curser.execute('''CREATE TABLE IF NOT EXISTS phonebook (
id integer PRIMARY KEY,
name TEXT ,
job TEXT ,
internal integer NULL,
direct integer NULL,
fax integer NULL,
IpPhone integer NULL
)''')
#fill database tabel with content of list
for i in tabel_list:
name=i
curser.execute('INSERT INTO phonebook (name,job,internal,direct,fax,IpPhone) VALUES (?,?,?,?,?,?)'
,(i)
)
conn.commit()