-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadExcel.py
More file actions
32 lines (30 loc) · 751 Bytes
/
Copy pathreadExcel.py
File metadata and controls
32 lines (30 loc) · 751 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
# -*- coding:utf-8 -*-
import pywintypes
import xlrd
import xlwt
import copy
import sys
import re
import xlutils.copy
# reload(sys)
# sys.setdefaultencoding("utf-8")
def read_excel():
data = xlrd.open_workbook("d:/1.xls")
table = data.sheet_by_name(u'Sheet1')
# print table.row_values(9)
rows = table.nrows
ans = []
h = re.compile(r'\d')
for i in range(rows):
ans.append(table.cell(i,0).value)
ans[i]=ans[i].replace(u'\xa0',u'')
ans[i]=ans[i].replace(u' ',u'')
ans[i]=ans[i].replace(u'、',u'')
ans[i]=h.sub('',ans[i]) #去掉字符串中的数字
table.put_cell(0, i, 1, ans[i], 0)
# print table.cell(i,0).value
# print ans[i]
wb = xlutils.copy.copy(data)
wb.save("d:/3.xls")
if __name__ == '__main__':
read_excel()