| @@ 459-526 (lines=68) @@ | ||
| 456 | len(reporting_period_data['timestamps']) == 0: |
|
| 457 | has_detail_data_flag = False |
|
| 458 | ||
| 459 | if has_detail_data_flag: |
|
| 460 | ws['B37'].font = title_font |
|
| 461 | ws['B37'] = name+' 能耗详情' |
|
| 462 | ||
| 463 | ws['B'+str(table_row)].fill = table_fill |
|
| 464 | ws['B'+str(table_row)].border = f_border |
|
| 465 | ws['B'+str(table_row)].alignment = c_c_alignment |
|
| 466 | ws['B'+str(table_row)] = '时间' |
|
| 467 | time = times[0] |
|
| 468 | has_data = False |
|
| 469 | max_row = 0 |
|
| 470 | if len(time) > 0: |
|
| 471 | has_data = True |
|
| 472 | max_row = table_row + len(time) |
|
| 473 | print("max_row", max_row) |
|
| 474 | ||
| 475 | if has_data: |
|
| 476 | for i in range(0, len(time)): |
|
| 477 | col = 'B' |
|
| 478 | row = str(table_row+1 + i) |
|
| 479 | # col = chr(ord('B') + i) |
|
| 480 | ws[col + row].font = title_font |
|
| 481 | ws[col + row].alignment = c_c_alignment |
|
| 482 | ws[col + row] = time[i] |
|
| 483 | ws[col + row].border = f_border |
|
| 484 | ||
| 485 | for i in range(0, ca_len): |
|
| 486 | # 38 title |
|
| 487 | col = chr(ord('C') + i) |
|
| 488 | ||
| 489 | ws[col + str(table_row)].fill = table_fill |
|
| 490 | ws[col + str(table_row)].font = title_font |
|
| 491 | ws[col + str(table_row)].alignment = c_c_alignment |
|
| 492 | ws[col + str(table_row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
| 493 | ws[col + str(table_row)].border = f_border |
|
| 494 | ||
| 495 | # 39 data |
|
| 496 | time = times[i] |
|
| 497 | time_len = len(time) |
|
| 498 | ||
| 499 | for j in range(0, time_len): |
|
| 500 | row = str(table_row+1 + j) |
|
| 501 | # col = chr(ord('B') + i) |
|
| 502 | ws[col + row].font = title_font |
|
| 503 | ws[col + row].alignment = c_c_alignment |
|
| 504 | ws[col + row] = round(reporting_period_data['values'][i][j], 0) |
|
| 505 | ws[col + row].border = f_border |
|
| 506 | # bar |
|
| 507 | # 39~: bar |
|
| 508 | bar = BarChart() |
|
| 509 | labels = Reference(ws, min_col=2, min_row=table_row+1, max_row=max_row + 1) |
|
| 510 | bar_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row + 1) # openpyxl bug |
|
| 511 | bar.add_data(bar_data, titles_from_data=True) |
|
| 512 | bar.set_categories(labels) |
|
| 513 | bar.height = 5.25 # cm 1.05*5 1.05cm = 30 pt |
|
| 514 | bar.width = 18 |
|
| 515 | # pie.title = "Pies sold by category" |
|
| 516 | bar.dLbls = DataLabelList() |
|
| 517 | # bar.dLbls.showCatName = True # label show |
|
| 518 | bar.dLbls.showVal = True # val show |
|
| 519 | bar.dLbls.showPercent = True # percent show |
|
| 520 | # s1 = CharacterProperties(sz=1800) # font size *100 |
|
| 521 | chart_col = 'B' |
|
| 522 | chart_cell = chart_col + str(38 + 5*i) |
|
| 523 | ws.add_chart(bar, chart_cell) |
|
| 524 | else: |
|
| 525 | for i in range(37, 69 + 1): |
|
| 526 | ws.row_dimensions[i].height = 0.1 |
|
| 527 | ||
| 528 | filename = str(uuid.uuid4()) + '.xlsx' |
|
| 529 | wb.save(filename) |
|
| @@ 400-461 (lines=62) @@ | ||
| 397 | len(reporting_period_data['timestamps']) == 0: |
|
| 398 | has_detail_data_flag = False |
|
| 399 | ||
| 400 | if has_detail_data_flag: |
|
| 401 | ws['B' + str(current_row_flag)].font = title_font |
|
| 402 | ws['B' + str(current_row_flag)] = name + ' 详细数据' |
|
| 403 | ||
| 404 | ws['B' + str(table_row)].fill = table_fill |
|
| 405 | ws['B' + str(table_row)].border = f_border |
|
| 406 | ws['B' + str(table_row)].alignment = c_c_alignment |
|
| 407 | ws['B' + str(table_row)] = '日期时间' |
|
| 408 | time = times[0] |
|
| 409 | has_data = False |
|
| 410 | max_row = 0 |
|
| 411 | if len(time) > 0: |
|
| 412 | has_data = True |
|
| 413 | max_row = table_row + len(time) |
|
| 414 | ||
| 415 | if has_data: |
|
| 416 | for i in range(0, len(time)): |
|
| 417 | col = 'B' |
|
| 418 | row = str(table_row + 1 + i) |
|
| 419 | ws[col + row].font = title_font |
|
| 420 | ws[col + row].alignment = c_c_alignment |
|
| 421 | ws[col + row] = time[i] |
|
| 422 | ws[col + row].border = f_border |
|
| 423 | ||
| 424 | for i in range(0, ca_len): |
|
| 425 | ||
| 426 | col = chr(ord('C') + i) |
|
| 427 | ||
| 428 | ws[col + str(table_row)].fill = table_fill |
|
| 429 | ws[col + str(table_row)].font = title_font |
|
| 430 | ws[col + str(table_row)].alignment = c_c_alignment |
|
| 431 | ws[col + str(table_row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][ |
|
| 432 | i] + ")" |
|
| 433 | ws[col + str(table_row)].border = f_border |
|
| 434 | ||
| 435 | # 39 data |
|
| 436 | time = times[i] |
|
| 437 | time_len = len(time) |
|
| 438 | ||
| 439 | for j in range(0, time_len): |
|
| 440 | row = str(table_row + 1 + j) |
|
| 441 | ws[col + row].font = title_font |
|
| 442 | ws[col + row].alignment = c_c_alignment |
|
| 443 | ws[col + row] = round(reporting_period_data['values'][i][j], 0) |
|
| 444 | ws[col + row].border = f_border |
|
| 445 | ||
| 446 | bar = BarChart() |
|
| 447 | labels = Reference(ws, min_col=2, min_row=table_row + 1, max_row=max_row) |
|
| 448 | bar_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row) |
|
| 449 | bar.add_data(bar_data, titles_from_data=True) |
|
| 450 | bar.set_categories(labels) |
|
| 451 | bar.height = 5.25 |
|
| 452 | bar.width = 18 |
|
| 453 | bar.dLbls = DataLabelList() |
|
| 454 | bar.dLbls.showVal = True |
|
| 455 | bar.dLbls.showPercent = True |
|
| 456 | chart_col = 'B' |
|
| 457 | chart_cell = chart_col + str(current_row_flag + 1 + 5 * i) |
|
| 458 | ws.add_chart(bar, chart_cell) |
|
| 459 | else: |
|
| 460 | for i in range(37, 69 + 1): |
|
| 461 | ws.row_dimensions[i].height = 0.1 |
|
| 462 | ||
| 463 | filename = str(uuid.uuid4()) + '.xlsx' |
|
| 464 | wb.save(filename) |
|