增加excel内容
This commit is contained in:
parent
22ee17509b
commit
aa801de348
50
lib/excel.py
50
lib/excel.py
@ -45,6 +45,15 @@ def upload_excel(request):
|
||||
else:
|
||||
return {'errcode': 700, 'errmsg': '文件格式不符'}
|
||||
|
||||
|
||||
# 函数用途:用于将含有“ ”的字符串,以“ ”分隔成数组形式
|
||||
# 参数:str: string
|
||||
# 返回值:arr: list
|
||||
def strToArrstr):
|
||||
tmp = str.split(" ")
|
||||
arr = map(int, tmp)
|
||||
return arr
|
||||
|
||||
# 加载excel文件
|
||||
def loadData(file_name, sheet_index):
|
||||
# 根据文件名加载文件
|
||||
@ -64,8 +73,33 @@ def loadData(file_name, sheet_index):
|
||||
keywords = row[0].value
|
||||
# 内容
|
||||
content = row[1].value
|
||||
# 浏览量
|
||||
num = row[2].value
|
||||
# 日期
|
||||
date = row[3].value
|
||||
# 标题
|
||||
title = row[4].value
|
||||
# 摘要
|
||||
digest = row[5].value
|
||||
# 更新时间
|
||||
update_time = row[6].value
|
||||
# 封面图链接
|
||||
cover = row[7].value
|
||||
# 图文链接
|
||||
url = row[8].value
|
||||
# 图文类型
|
||||
type = row[9].value
|
||||
|
||||
# 这样就是 key:value的形式
|
||||
data_list[keywords] = content
|
||||
data_list["num"] = num
|
||||
date_list["date"] = date
|
||||
date_list["news"]["title"] = title
|
||||
date_list["news"]["digest"] = digest
|
||||
date_list["news"]["update_time"] = update_time
|
||||
date_list["news"]["cover"] = cover
|
||||
date_list["news"]["url"] = url
|
||||
date_list["news"]["type"] = strToArr(type)
|
||||
index += 1
|
||||
return data_list
|
||||
|
||||
@ -116,6 +150,22 @@ def createWorkBook(data_list):
|
||||
ws.cell(row=index, column= 1).value = keywords
|
||||
# 第二列放内容
|
||||
ws.cell(row=index, column= 2).value = data_list[keywords]
|
||||
# 浏览量
|
||||
ws.cell(row=index, column= 3).value = data_list["num"]
|
||||
# 日期
|
||||
ws.cell(row=index, column= 4).value = data_list["date"]
|
||||
# 标题
|
||||
ws.cell(row=index, column= 5).value = data_list["news"]["title"]
|
||||
# 摘要
|
||||
ws.cell(row=index, column= 6).value = data_list["news"]["digest"]
|
||||
# 更新时间
|
||||
ws.cell(row=index, column= 7).value = data_list["news"]["update_time"]
|
||||
# 封面图
|
||||
ws.cell(row=index, column= 8).value = data_list["news"]["cover"]
|
||||
# 链接
|
||||
ws.cell(row=index, column= 9).value = data_list["news"]["url"]
|
||||
# 类型
|
||||
ws.cell(row=index, column= 10).value = data_list["news"]["type"]
|
||||
index += 1
|
||||
# 获取一个唯一的文件名
|
||||
new_filename = create_uuid() + '.xlsx'
|
||||
|
Loading…
x
Reference in New Issue
Block a user