-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcase.py
More file actions
61 lines (56 loc) · 2.06 KB
/
testcase.py
File metadata and controls
61 lines (56 loc) · 2.06 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
import xlwt
list=[]
def parsefile(filepath, mark):
l=[]
begin = time.time()
#[des_filename, extname] = os.path.splitext(filepath)
#nfilename = des_filename + '_' + str("r") + extname
f_read = open(filepath, encoding='UTF-8')
i=1
for eachline in f_read:
if i == 1:
splitarr=eachline.split(mark)
list.append(splitarr)
i = i+1
else:
splitarr = eachline.split(mark)
l.append(splitarr)
l= sorted(l,key=lambda num : num[0])
list.extend(l)
f_read.close()
end = time.time()
print("[info]======>format file %s ,spend time %d s" % (filepath, (end - begin)))
def create_xls(file_path, list):
styleBlueBkg = xlwt.easyxf('pattern: pattern solid, fore_colour blue; font: bold on;')
styleredBkg = xlwt.easyxf('pattern: pattern solid, fore_colour red;')
styleyellowBkg = xlwt.easyxf('pattern: pattern solid, fore_colour yellow;')
workbook = xlwt.Workbook(encoding='utf-8')
sheet1 = workbook.add_sheet('库存状态', cell_overwrite_ok=True)
for i, j in enumerate(list):
if i == 0:
print(" come to line %s " % (i + 1))
for s, k in enumerate(j):
sheet1.write(i, s, str(k), styleBlueBkg)
else:
for s, k in enumerate(j):
if str(k) == '无货':
sheet1.write(i, 1, str(j[1]), styleyellowBkg)
if len(j) < 4 :
sheet1.write(i, 1, str(j[1]), styleredBkg)
sheet1.write(i, s, str(k))
file_path = file_path.replace('\\', '/')
workbook.save(file_path)
print('csv to excel finish!')
return file_path
if __name__ == '__main__':
srcfile = '/home/znniwal/study/inventory.csv'
floder = os.path.dirname(os.path.realpath(__file__))
srcfile = floder + u'/inventory.csv'
print("srcfile:%s" % (srcfile))
[des_filename, extname] = os.path.splitext(srcfile)
parsefile(srcfile, ',')
create_xls(des_filename + u"_r.xls", list)