-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPosition.py
More file actions
37 lines (33 loc) · 988 Bytes
/
Copy pathgetPosition.py
File metadata and controls
37 lines (33 loc) · 988 Bytes
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
import xlrd
import openpyxl
# 处理地级市经纬度
data = xlrd.open_workbook('./resources/positions.xls')
# 获取表格数据(从sheet中)
table = data.sheets()[0]
# 临时仓库
storage = list()
# 获取数据
positions = table.col_values(0)[1:]
for position in positions:
current = position.split(",")
current[2] = current[2][1:-1]
storage.append(current)
# 将数据导入新excel中
newExl = openpyxl.Workbook()
sheet = newExl.create_sheet()
# 表头
row0 = ['地点', '经度', '纬度']
sheet.append(row0)
# 添加数据
for i in storage:
i_position, i_longitude, i_latitude = i[2], i[0], i[1]
i_current = [i_position, i_longitude, i_latitude]
sheet.append(i_current)
# 储存
newExl.save(filename = './export/position/test.xlsx')
# 删除多余sheet
delWb = openpyxl.load_workbook('./export/position/test.xlsx')
ws = delWb["Sheet"]
delWb.remove(ws)
delWb.save('./export/position/test.xlsx')
print("Success!")