import xlrd
from xlutils.copy import copy
def read_data():
wb=xlrd.open_workbook('./base_data/data01.xlsx')
sh=wb.sheet_by_index(0)
fen_type={}
count_price=[]
for r in range(sh.nrows):
count=sh.cell_value(r,3)
count_price.append(count)
key=sh.cell_value(r,0)
if fen_type.get(key):
fen_type[key]+=count
else:
fen_type[key]=count
return fen_type,count_price
def save(fen,count):
wb=xlrd.open_workbook('./base_data/data01.xlsx')
sh_t=wb.sheet_by_index(0)
wb2=copy(wb)
sh=wb2.get_sheet(0)
for r in range(sh_t.nrows):
sh.write(r,sh_t.ncols,count[r])
sh2=wb2,add_sheet('汇总数据')
for i,key in enumerate(fen.keys()):
sh2.write(i,0,key)
sh2.write(i,1,fen.get(key))
wb2.save('05_汇总数据.xlsx')
if __name__=="__main__":
f,c=read_data()
save(f,c)
PS D:\菁菁小私库\VScode> & "C:/Program Files (x86)/Python38-32/python.exe" d:/菁菁小私库/VScode/office办公自动化/05_统计数据.py
Traceback (most recent call last):
File "d:/菁菁小私库/VScode/office办公自动化/05_统计数据.py", line 35, in <module>
f,c=read_data()
File "d:/菁菁小私库/VScode/office办公自动化/05_统计数据.py", line 5, in read_data
wb=xlrd.open_workbook('./base_data/data01.xlsx')
File "C:\Users\旸kn\AppData\Roaming\Python\Python38\site-packages\xlrd\__init__.py", line 170, in open_workbook
raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported
PS D:\菁菁小私库\VScode>