2021/4/26
parent
7e18d31887
commit
d36b37133f
|
@ -423,103 +423,6 @@ def generate_excel(report,
|
||||||
else:
|
else:
|
||||||
for i in range(12, 18 + 1):
|
for i in range(12, 18 + 1):
|
||||||
ws.row_dimensions[i].height = 0.1
|
ws.row_dimensions[i].height = 0.1
|
||||||
# end_row 10
|
|
||||||
# start_row 12
|
|
||||||
################################################
|
|
||||||
# Third: 子空间能耗
|
|
||||||
# 19: title
|
|
||||||
# 20: table title
|
|
||||||
# 21~24 table_data
|
|
||||||
# Total: 6 rows
|
|
||||||
################################################
|
|
||||||
has_child_flag = True
|
|
||||||
# Judge if the space has child space, if not, delete it.
|
|
||||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
|
||||||
len(report['child_space']["energy_category_names"]) == 0 \
|
|
||||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
|
||||||
or report['child_space']['energy_category_names'] is None \
|
|
||||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
|
||||||
or len(report['child_space']['child_space_nchild_space_names_arrayames_array'][0]) == 0:
|
|
||||||
|
|
||||||
has_child_flag = False
|
|
||||||
|
|
||||||
current_row_number = 19
|
|
||||||
|
|
||||||
if has_child_flag:
|
|
||||||
child = report['child_space']
|
|
||||||
|
|
||||||
ws['B19'].font = title_font
|
|
||||||
ws['B19'] = name+' 子空间能耗'
|
|
||||||
|
|
||||||
ws.row_dimensions[20].height = 60
|
|
||||||
ws['B20'].fill = table_fill
|
|
||||||
ws['B20'].border = f_border
|
|
||||||
ca_len = len(child['energy_category_names'])
|
|
||||||
|
|
||||||
table_start_row_number = 20
|
|
||||||
|
|
||||||
for i in range(0, ca_len):
|
|
||||||
row = chr(ord('C') + i)
|
|
||||||
ws[row + '20'].fill = table_fill
|
|
||||||
ws[row + '20'].font = title_font
|
|
||||||
ws[row + '20'].alignment = c_c_alignment
|
|
||||||
ws[row + '20'].border = f_border
|
|
||||||
ws[row + '20'] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
|
||||||
|
|
||||||
space_len = len(child['child_space_names_array'][0])
|
|
||||||
|
|
||||||
for i in range(0, space_len):
|
|
||||||
row = str(i + 21)
|
|
||||||
|
|
||||||
ws['B' + row].font = name_font
|
|
||||||
ws['B' + row].alignment = c_c_alignment
|
|
||||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
|
||||||
ws['B' + row].border = f_border
|
|
||||||
|
|
||||||
for j in range(0, ca_len):
|
|
||||||
col = chr(ord('C') + j)
|
|
||||||
ws[col + row].font = name_font
|
|
||||||
ws[col + row].alignment = c_c_alignment
|
|
||||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
|
||||||
ws[col + row].border = f_border
|
|
||||||
|
|
||||||
table_end_row_number = 20 + space_len
|
|
||||||
chart_start_row_number = 20 + space_len + 1
|
|
||||||
|
|
||||||
for i in range(0, ca_len):
|
|
||||||
# pie
|
|
||||||
# 25~30: pie
|
|
||||||
pie = PieChart()
|
|
||||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
|
||||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
|
||||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
|
||||||
pie.add_data(pie_data, titles_from_data=True)
|
|
||||||
pie.set_categories(labels)
|
|
||||||
pie.height = 6.6 # cm 1.05*5 1.05cm = 30 pt
|
|
||||||
pie.width = 8
|
|
||||||
# pie.title = "Pies sold by category"
|
|
||||||
s1 = pie.series[0]
|
|
||||||
s1.dLbls = DataLabelList()
|
|
||||||
s1.dLbls.showCatName = False # 标签显示
|
|
||||||
s1.dLbls.showVal = True # 数量显示
|
|
||||||
s1.dLbls.showPercent = True # 百分比显示
|
|
||||||
# s1 = CharacterProperties(sz=1800) # 图表中字体大小 *100
|
|
||||||
if i % 2 == 0:
|
|
||||||
chart_cell = 'B' + str(chart_start_row_number)
|
|
||||||
else:
|
|
||||||
chart_cell = 'E' + str(chart_start_row_number)
|
|
||||||
chart_start_row_number += 5
|
|
||||||
# ws.add_chart(pie, chart_cell)
|
|
||||||
# chart_col = chr(ord('B') + 2 * j)
|
|
||||||
# chart_cell = chart_col + '25'
|
|
||||||
ws.add_chart(pie, chart_cell)
|
|
||||||
|
|
||||||
current_row_number = chart_start_row_number
|
|
||||||
|
|
||||||
if ca_len % 2 == 1:
|
|
||||||
current_row_number += 5
|
|
||||||
|
|
||||||
current_row_number += 1
|
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
# Fourth: 能耗详情
|
# Fourth: 能耗详情
|
||||||
|
@ -528,6 +431,7 @@ def generate_excel(report,
|
||||||
# current_row_number+1+ca_len*6: table title
|
# current_row_number+1+ca_len*6: table title
|
||||||
# current_row_number+1+ca_len*6~: table_data
|
# current_row_number+1+ca_len*6~: table_data
|
||||||
################################################
|
################################################
|
||||||
|
current_row_number = 19
|
||||||
reporting_period_data = report['reporting_period']
|
reporting_period_data = report['reporting_period']
|
||||||
times = reporting_period_data['timestamps']
|
times = reporting_period_data['timestamps']
|
||||||
has_detail_data_flag = True
|
has_detail_data_flag = True
|
||||||
|
@ -824,3 +728,4 @@ def generate_excel(report,
|
||||||
wb.save(filename)
|
wb.save(filename)
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue