1. Change the subspace location
parent
811d0cba0d
commit
498d33d278
|
@ -428,103 +428,6 @@ def generate_excel(report,
|
|||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'D' + str(chart_start_row_number))
|
||||
|
||||
#############################################
|
||||
|
||||
has_child_space_data_flag = True
|
||||
|
||||
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_names_array'][0]) == 0:
|
||||
has_child_space_data_flag = False
|
||||
|
||||
if has_child_space_data_flag:
|
||||
child_space_data = report['child_space']
|
||||
ca_len = len(child_space_data['energy_category_names'])
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
child_space_data['energy_category_names'][i] + " (" + child_space_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
ca_child_len = len(child_space_data['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, ca_child_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = child_space_data['child_space_names_array'][0][i]
|
||||
current_row_number += 1
|
||||
|
||||
current_row_number -= ca_child_len
|
||||
|
||||
for i in range(0, ca_child_len):
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(child_space_data['subtotals_saving_array'][j][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'B'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
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.title = reporting_period_data['names'][i] + " (" + \
|
||||
reporting_period_data['units'][i] + ")"
|
||||
pie.height = 6.6
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(current_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(current_row_number)
|
||||
current_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
# ws.add_chart(pie, col + str(current_row_number))
|
||||
# col = chr(ord(col) + 2)
|
||||
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
################################
|
||||
|
||||
has_values_saving_data = True
|
||||
|
@ -656,6 +559,101 @@ def generate_excel(report,
|
|||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
#############################################
|
||||
|
||||
has_child_space_data_flag = True
|
||||
|
||||
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_names_array'][0]) == 0:
|
||||
has_child_space_data_flag = False
|
||||
|
||||
if has_child_space_data_flag:
|
||||
child_space_data = report['child_space']
|
||||
ca_len = len(child_space_data['energy_category_names'])
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
child_space_data['energy_category_names'][i] + " (" + child_space_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
ca_child_len = len(child_space_data['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, ca_child_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = child_space_data['child_space_names_array'][0][i]
|
||||
current_row_number += 1
|
||||
|
||||
current_row_number -= ca_child_len
|
||||
|
||||
for i in range(0, ca_child_len):
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(child_space_data['subtotals_saving_array'][j][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'B'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
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.title = reporting_period_data['names'][i] + " (" + \
|
||||
reporting_period_data['units'][i] + ")"
|
||||
pie.height = 6.6
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(current_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(current_row_number)
|
||||
current_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
|
|
Loading…
Reference in New Issue