-
Notifications
You must be signed in to change notification settings - Fork 1
/
dealWithHsDs.py
68 lines (60 loc) · 2.04 KB
/
dealWithHsDs.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding=utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import json
import sys
import xlrd
import xlwt
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = 'SimSun' # 指定“宋体”
style.font = font
BaseDicPath = "/program/dic/sources"
try:
xls = xlrd.open_workbook(sys.argv[1])
sheetNames = xls.sheet_names()
# sheet = xls.sheet_by_name("Sheet1")
sheet = xls.sheet_by_name("SQL Results")
title = ['TABLE_NAME', 'COMMENTS', 'COLUMN_NAME', 'COMMENTS', 'DATA_TYPE',
'DATA_LENGTH', 'NULLABLE', 'COLUMN_ID']
ncols = len(title)
preTableName = ''
curTableName = ''
workbook_t = None
sheet_t = None
row_wt = 0
for row in range(1, sheet.nrows):
try:
preTableName = curTableName
curTableName = sheet.cell_value(row, 1)
if not preTableName == curTableName:
row_wt = 0
# 保存上一张表
if workbook_t is not None:
try:
workbook_t.save(BaseDicPath + "/" + preTableName + ".xls")
except Exception, e:
print Exception, ":", e
tbNameCn = sheet.cell_value(row, 4)
if tbNameCn is None or tbNameCn == '':
tbNameCn = '未知'
print 'tbNameCn:', tbNameCn
workbook_t = xlwt.Workbook(encoding='utf-8')
sheet_t = workbook_t.add_sheet(tbNameCn, cell_overwrite_ok=True)
# add title
for col in range(1, ncols + 1):
sheet_t.write(row_wt, col, title[col-1], style)
row_wt += 1
for col in range(1, ncols + 1):
sheet_t.write(row_wt, col, sheet.cell_value(row, col), style)
except Exception, e:
print Exception, ":", e
# 保存上一张表
if workbook_t is not None:
workbook_t.save(BaseDicPath + "/" + preTableName + ".xls")
except Exception, e:
print Exception, ":", e
exit(-1)
finally:
exit(0)