1.使用uuid进行唯一编码,写入新文件
file_name = 'case_%s.xls'%(uuid.uuid4().hex)
2.如果文件路径不存在,就创建。
if not os.path.exists(path_store):
os.makedirs(path_store)
3.打开并写入文件
with open(upload_path, 'wb+') as f2:
content = f.read()
f2.write(content)
这里的upload_path指的是具体到文件名称的文件路径,f指前端传入的文件
4.使用Python的xlrd库读取文件内容
data = xlrd.open_workbook(upload_path)
sheet = data.sheet_by_name("sheet1")
5.写入前将每行数据提取
for i in range(0, sheet.nrows):
returnData = sheet.row_values(i)
6.有用到Python的集合,利用集合中没有重复元素这一特性去重。
case_belong_set = set()#定义集合
case_belong_set.add(ca