python处理Excel自动统计表
使用python库xlutils、xlrd、xlwt。
设计思路
使用xlrd.open_workbook读取统计数据表
做一个总数据的空列表,
使用for循环将使用的数据以字典的形式存储在总列表中
将汇总的数据通过if的条件判断分配写入不同的列表中
通过xlutils套用格式,写入到自动统计表中
python的脚本范例
from xlutils.copy import copy
import xlrd
import xlwt
xlsx = xlrd.open_workbook(r'D:\python_work\1\CourseCode\Chapter1\S1-1-3\LessonCode\7月下旬入库表.xlsx')
table = xlsx.sheet_by_index(0)
all_data = []
for i in range(1, table.nrows):
company = table.cell_value(i, 1)
price = table.cell_value(i, 3)
weight = table.cell_value(i, 4)
data = {'company': company, 'price': price, 'weight': weight}
all_data.append(data)
a_weight = []
a_total_price = []
b_weight = []
b_total_price = []