import xlrd
import xlwt
from xlutils.copy import copy
xlsx = xlrd.open_workbook(".\\files\\入庫表.xlsx")
table = xlsx.sheet_by_index(0)
all_data = []
for n in range(1,table.nrows):
company = table.cell(n, 1).value
price = table.cell(n, 3).value
weight = table.cell(n, 4).value
data = {'company': company, 'weight': weight, 'price': price}
all_data.append(data)
a_weight = []
a_total_price = []
b_weight = []
b_total_price = []
c_weight = []
c_total_price = []
d_weight = []
d_total_price = []
for i in all_data:
if i['company'] == '張三糧配':
a_weight.append(i['weight'])
a_total_price.append(i['weight'] * i['price'])
if i['company'] == '李四糧配'
b_weight.append(i['weight'])
b_total_price.append(i['weight'] * i['price'])
if i['company'] == '王五小麥'
c_weight.append(i['weight'])
c_total_price.append(i['weight'] * i['price'])
if i['company'] == '趙六麥子專營'
d_weight.append(i['weight'])
d_total_price.append(i['weight'] * i['price'])
tem_excel = xlrd.open_workbook(".\\files\\統(tǒng)計表_模板.xls", formatting_info=True)
tem_sheet = tem_excel.sheet_by_index(0)
new_excel = copy(tem_excel)
new_sheet = new_excel.get_sheet(0)
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = '微軟雅黑'
font.bold = True
font.height = 360
style.font = font
borders = xlwt.Borders()
borders.top = xlwt.Borders.THIN
borders.bottom = xlwt.Borders.THIN
borders.left = xlwt.Borders.THIN
borders.right = xlwt.Borders.THIN
style.borders = borders
alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_CENTER
alignment.vert = xlwt.Alignment.VERT_CENTER
style.alignment = alignment
new_sheet.write(2, 1, len(a_weight), style)
new_sheet.write(2, 2, round(sum(a_weight), 2), style)
new_sheet.write(2, 3, round(sum(a_total_price), 2), style)
new_sheet.write(3, 1, len(b_weight), style)
new_sheet.write(3, 2, round(sum(b_weight), 2), style)
new_sheet.write(3, 3, round(sum(b_total_price), 2), style)
new_sheet.write(4, 1, len(c_weight), style)
new_sheet.write(4, 2, round(sum(c_weight), 2), style)
new_sheet.write(4, 3, round(sum(c_total_price), 2), style)
new_sheet.write(5, 1, len(d_weight), style)
new_sheet.write(5, 2, round(sum(d_weight), 2), style)
new_sheet.write(5, 3, round(sum(d_total_price), 2), style)
new_excel.save(".\\output\\統(tǒng)計表填寫.xls")
P14自動生成統(tǒng)計報表
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 文章引用自網(wǎng)易云課堂《用Python自動辦公,做職場高手》網(wǎng)址:https://study.163.com/cou...
- 概述 提供指定的接口,為測試人員提供好用的測試報告存儲,顯示及分享的系統(tǒng)。 主要功能包括: 判定測試 壓力測試 響...
- 日常工作流程:打開收藏夾網(wǎng)頁,點擊下載,數(shù)據(jù)就下載完畢。簡化工作流程提高效率。 實現(xiàn)原理:Google Sheet...
- 數(shù)據(jù)分析師肯定每天都被各種各樣的數(shù)據(jù)數(shù)據(jù)報表搞得焦頭爛額,老板的,運營的、產(chǎn)品的等等。而且大部分報表都是重復(fù)性的工...