Code Duplication    Length = 250-250 lines in 2 locations

excelexporters/spacesaving.py 1 location

@@ 180-429 (lines=250) @@
177
            len(reporting_period_data['names']) == 0:
178
        has_names_data_flag = False
179
180
    if has_names_data_flag:
181
        ws['B' + str(current_row_number)].font = title_font
182
        ws['B' + str(current_row_number)] = name + ' 报告期节约'
183
184
        current_row_number += 1
185
186
        category = reporting_period_data['names']
187
        ca_len = len(category)
188
189
        ws.row_dimensions[current_row_number].height = 75
190
        ws['B' + str(current_row_number)].fill = table_fill
191
        ws['B' + str(current_row_number)].border = f_border
192
193
        col = 'C'
194
195
        for i in range(0, ca_len):
196
            ws[col + str(current_row_number)].fill = table_fill
197
            ws[col + str(current_row_number)].font = name_font
198
            ws[col + str(current_row_number)].alignment = c_c_alignment
199
            ws[col + str(current_row_number)].border = f_border
200
            ws[col + str(current_row_number)] = \
201
                reporting_period_data['names'][i] + " (基线-实际) (" + reporting_period_data['units'][i] + ")"
202
203
            col = chr(ord(col) + 1)
204
205
        ws[col + str(current_row_number)].fill = table_fill
206
        ws[col + str(current_row_number)].font = name_font
207
        ws[col + str(current_row_number)].alignment = c_c_alignment
208
        ws[col + str(current_row_number)].border = f_border
209
        ws[col + str(current_row_number)] = '吨标准煤 (基线-实际) (TCE)'
210
211
        col = chr(ord(col) + 1)
212
213
        ws[col + str(current_row_number)].fill = table_fill
214
        ws[col + str(current_row_number)].font = name_font
215
        ws[col + str(current_row_number)].alignment = c_c_alignment
216
        ws[col + str(current_row_number)].border = f_border
217
        ws[col + str(current_row_number)] = '吨二氧化碳排放 (基线-实际) (TCO2E)'
218
219
        col = chr(ord(col) + 1)
220
221
        current_row_number += 1
222
223
        ws['B' + str(current_row_number)].font = title_font
224
        ws['B' + str(current_row_number)].alignment = c_c_alignment
225
        ws['B' + str(current_row_number)].border = f_border
226
        ws['B' + str(current_row_number)] = '节约'
227
228
        col = 'C'
229
230
        for i in range(0, ca_len):
231
            ws[col + str(current_row_number)].font = name_font
232
            ws[col + str(current_row_number)].alignment = c_c_alignment
233
            ws[col + str(current_row_number)].border = f_border
234
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
235
236
            col = chr(ord(col) + 1)
237
238
        ws[col + str(current_row_number)].font = name_font
239
        ws[col + str(current_row_number)].alignment = c_c_alignment
240
        ws[col + str(current_row_number)].border = f_border
241
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_saving'] / 1000, 2)
242
243
        col = chr(ord(col) + 1)
244
245
        ws[col + str(current_row_number)].font = name_font
246
        ws[col + str(current_row_number)].alignment = c_c_alignment
247
        ws[col + str(current_row_number)].border = f_border
248
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2)
249
250
        col = chr(ord(col) + 1)
251
252
        current_row_number += 1
253
254
        ws['B' + str(current_row_number)].font = title_font
255
        ws['B' + str(current_row_number)].alignment = c_c_alignment
256
        ws['B' + str(current_row_number)].border = f_border
257
        ws['B' + str(current_row_number)] = '单位面积值'
258
259
        col = 'C'
260
261
        for i in range(0, ca_len):
262
            ws[col + str(current_row_number)].font = name_font
263
            ws[col + str(current_row_number)].alignment = c_c_alignment
264
            ws[col + str(current_row_number)].border = f_border
265
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area_saving'][i], 2)
266
267
            col = chr(ord(col) + 1)
268
269
        ws[col + str(current_row_number)].font = name_font
270
        ws[col + str(current_row_number)].alignment = c_c_alignment
271
        ws[col + str(current_row_number)].border = f_border
272
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2)
273
274
        col = chr(ord(col) + 1)
275
276
        ws[col + str(current_row_number)].font = name_font
277
        ws[col + str(current_row_number)].alignment = c_c_alignment
278
        ws[col + str(current_row_number)].border = f_border
279
        ws[col + str(current_row_number)] = \
280
            round(reporting_period_data['total_in_kgco2e_per_unit_area_saving'] / 1000, 2)
281
282
        col = chr(ord(col) + 1)
283
284
        current_row_number += 1
285
286
        ws['B' + str(current_row_number)].font = title_font
287
        ws['B' + str(current_row_number)].alignment = c_c_alignment
288
        ws['B' + str(current_row_number)].border = f_border
289
        ws['B' + str(current_row_number)] = '环比'
290
291
        col = 'C'
292
293
        for i in range(0, ca_len):
294
            ws[col + str(current_row_number)].font = name_font
295
            ws[col + str(current_row_number)].alignment = c_c_alignment
296
            ws[col + str(current_row_number)].border = f_border
297
            ws[col + str(current_row_number)] = str(
298
                round(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \
299
                if reporting_period_data['increment_rates_saving'][i] is not None else '-'
300
301
            col = chr(ord(col) + 1)
302
303
        ws[col + str(current_row_number)].font = name_font
304
        ws[col + str(current_row_number)].alignment = c_c_alignment
305
        ws[col + str(current_row_number)].border = f_border
306
        ws[col + str(current_row_number)] = str(
307
            round(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \
308
            if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-'
309
310
        col = chr(ord(col) + 1)
311
312
        ws[col + str(current_row_number)].font = name_font
313
        ws[col + str(current_row_number)].alignment = c_c_alignment
314
        ws[col + str(current_row_number)].border = f_border
315
        ws[col + str(current_row_number)] = str(
316
            round(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \
317
            if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-'
318
319
        col = chr(ord(col) + 1)
320
321
        current_row_number += 2
322
323
        ws['B' + str(current_row_number)].font = title_font
324
        ws['B' + str(current_row_number)] = name + ' 吨标准煤(TCE)占比'
325
326
        current_row_number += 1
327
        table_start_row_number = current_row_number
328
        chart_start_row_number = current_row_number
329
330
        ws.row_dimensions[current_row_number].height = 60
331
        ws['B' + str(current_row_number)].fill = table_fill
332
        ws['B' + str(current_row_number)].border = f_border
333
334
        ws['C' + str(current_row_number)].fill = table_fill
335
        ws['C' + str(current_row_number)].font = name_font
336
        ws['C' + str(current_row_number)].alignment = c_c_alignment
337
        ws['C' + str(current_row_number)].border = f_border
338
        ws['C' + str(current_row_number)] = '吨标准煤(TCE)占比'
339
340
        current_row_number += 1
341
342
        for i in range(0, ca_len):
343
            ws['B' + str(current_row_number)].font = title_font
344
            ws['B' + str(current_row_number)].alignment = c_c_alignment
345
            ws['B' + str(current_row_number)].border = f_border
346
            ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
347
348
            ws['C' + str(current_row_number)].font = name_font
349
            ws['C' + str(current_row_number)].alignment = c_c_alignment
350
            ws['C' + str(current_row_number)].border = f_border
351
            ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
352
353
            current_row_number += 1
354
355
        table_end_row_number = current_row_number - 1
356
357
        if ca_len < 4:
358
            current_row_number = current_row_number - ca_len + 4
359
360
        current_row_number += 1
361
362
        pie = PieChart()
363
        pie.title = name + ' 吨标准煤(TCE)占比'
364
        labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
365
        pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
366
        pie.add_data(pie_data, titles_from_data=True)
367
        pie.set_categories(labels)
368
        pie.height = 7.25
369
        pie.width = 9
370
        s1 = pie.series[0]
371
        s1.dLbls = DataLabelList()
372
        s1.dLbls.showCatName = False
373
        s1.dLbls.showVal = True
374
        s1.dLbls.showPercent = True
375
        ws.add_chart(pie, 'D' + str(chart_start_row_number))
376
377
        ws['B' + str(current_row_number)].font = title_font
378
        ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
379
380
        current_row_number += 1
381
        table_start_row_number = current_row_number
382
        chart_start_row_number = current_row_number
383
384
        ws.row_dimensions[current_row_number].height = 60
385
        ws['B' + str(current_row_number)].fill = table_fill
386
        ws['B' + str(current_row_number)].border = f_border
387
388
        ws['C' + str(current_row_number)].fill = table_fill
389
        ws['C' + str(current_row_number)].font = name_font
390
        ws['C' + str(current_row_number)].alignment = c_c_alignment
391
        ws['C' + str(current_row_number)].border = f_border
392
        ws['C' + str(current_row_number)] = '吨二氧化碳排放(TCO2E)占比'
393
394
        current_row_number += 1
395
396
        for i in range(0, ca_len):
397
            ws['B' + str(current_row_number)].font = title_font
398
            ws['B' + str(current_row_number)].alignment = c_c_alignment
399
            ws['B' + str(current_row_number)].border = f_border
400
            ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
401
402
            ws['C' + str(current_row_number)].font = name_font
403
            ws['C' + str(current_row_number)].alignment = c_c_alignment
404
            ws['C' + str(current_row_number)].border = f_border
405
            ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
406
407
            current_row_number += 1
408
409
        table_end_row_number = current_row_number - 1
410
411
        if ca_len < 4:
412
            current_row_number = current_row_number - ca_len + 4
413
414
        current_row_number += 1
415
416
        pie = PieChart()
417
        pie.title = name + ' 吨二氧化碳排放(TCO2E)占比'
418
        labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
419
        pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
420
        pie.add_data(pie_data, titles_from_data=True)
421
        pie.set_categories(labels)
422
        pie.height = 7.25
423
        pie.width = 9
424
        s1 = pie.series[0]
425
        s1.dLbls = DataLabelList()
426
        s1.dLbls.showCatName = False
427
        s1.dLbls.showVal = True
428
        s1.dLbls.showPercent = True
429
        ws.add_chart(pie, 'D' + str(chart_start_row_number))
430
431
    #############################################
432

excelexporters/tenantsaving.py 1 location

@@ 180-429 (lines=250) @@
177
            len(reporting_period_data['names']) == 0:
178
        has_names_data_flag = False
179
180
    if has_names_data_flag:
181
        ws['B' + str(current_row_number)].font = title_font
182
        ws['B' + str(current_row_number)] = name + ' 报告期节约'
183
184
        current_row_number += 1
185
186
        category = reporting_period_data['names']
187
        ca_len = len(category)
188
189
        ws.row_dimensions[current_row_number].height = 75.0
190
        ws['B' + str(current_row_number)].fill = table_fill
191
        ws['B' + str(current_row_number)].border = f_border
192
193
        col = 'C'
194
195
        for i in range(0, ca_len):
196
            ws[col + str(current_row_number)].fill = table_fill
197
            ws[col + str(current_row_number)].font = name_font
198
            ws[col + str(current_row_number)].alignment = c_c_alignment
199
            ws[col + str(current_row_number)].border = f_border
200
            ws[col + str(current_row_number)] = \
201
                reporting_period_data['names'][i] + " (基线-实际) (" + reporting_period_data['units'][i] + ")"
202
203
            col = chr(ord(col) + 1)
204
205
        ws[col + str(current_row_number)].fill = table_fill
206
        ws[col + str(current_row_number)].font = name_font
207
        ws[col + str(current_row_number)].alignment = c_c_alignment
208
        ws[col + str(current_row_number)].border = f_border
209
        ws[col + str(current_row_number)] = '吨标准煤 (基线-实际) (TCE)'
210
211
        col = chr(ord(col) + 1)
212
213
        ws[col + str(current_row_number)].fill = table_fill
214
        ws[col + str(current_row_number)].font = name_font
215
        ws[col + str(current_row_number)].alignment = c_c_alignment
216
        ws[col + str(current_row_number)].border = f_border
217
        ws[col + str(current_row_number)] = '吨二氧化碳排放 (基线-实际) (TCO2E)'
218
219
        col = chr(ord(col) + 1)
220
221
        current_row_number += 1
222
223
        ws['B' + str(current_row_number)].font = title_font
224
        ws['B' + str(current_row_number)].alignment = c_c_alignment
225
        ws['B' + str(current_row_number)].border = f_border
226
        ws['B' + str(current_row_number)] = '节约'
227
228
        col = 'C'
229
230
        for i in range(0, ca_len):
231
            ws[col + str(current_row_number)].font = name_font
232
            ws[col + str(current_row_number)].alignment = c_c_alignment
233
            ws[col + str(current_row_number)].border = f_border
234
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
235
236
            col = chr(ord(col) + 1)
237
238
        ws[col + str(current_row_number)].font = name_font
239
        ws[col + str(current_row_number)].alignment = c_c_alignment
240
        ws[col + str(current_row_number)].border = f_border
241
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_saving'] / 1000, 2)
242
243
        col = chr(ord(col) + 1)
244
245
        ws[col + str(current_row_number)].font = name_font
246
        ws[col + str(current_row_number)].alignment = c_c_alignment
247
        ws[col + str(current_row_number)].border = f_border
248
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2)
249
250
        col = chr(ord(col) + 1)
251
252
        current_row_number += 1
253
254
        ws['B' + str(current_row_number)].font = title_font
255
        ws['B' + str(current_row_number)].alignment = c_c_alignment
256
        ws['B' + str(current_row_number)].border = f_border
257
        ws['B' + str(current_row_number)] = '单位面积值'
258
259
        col = 'C'
260
261
        for i in range(0, ca_len):
262
            ws[col + str(current_row_number)].font = name_font
263
            ws[col + str(current_row_number)].alignment = c_c_alignment
264
            ws[col + str(current_row_number)].border = f_border
265
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area_saving'][i], 2)
266
267
            col = chr(ord(col) + 1)
268
269
        ws[col + str(current_row_number)].font = name_font
270
        ws[col + str(current_row_number)].alignment = c_c_alignment
271
        ws[col + str(current_row_number)].border = f_border
272
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgco2e_per_unit_area_saving']
273
                                                  / 1000, 2)
274
275
        col = chr(ord(col) + 1)
276
277
        ws[col + str(current_row_number)].font = name_font
278
        ws[col + str(current_row_number)].alignment = c_c_alignment
279
        ws[col + str(current_row_number)].border = f_border
280
        ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2)
281
282
        col = chr(ord(col) + 1)
283
284
        current_row_number += 1
285
286
        ws['B' + str(current_row_number)].font = title_font
287
        ws['B' + str(current_row_number)].alignment = c_c_alignment
288
        ws['B' + str(current_row_number)].border = f_border
289
        ws['B' + str(current_row_number)] = '环比'
290
291
        col = 'C'
292
293
        for i in range(0, ca_len):
294
            ws[col + str(current_row_number)].font = name_font
295
            ws[col + str(current_row_number)].alignment = c_c_alignment
296
            ws[col + str(current_row_number)].border = f_border
297
            ws[col + str(current_row_number)] = str(
298
                round(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \
299
                if reporting_period_data['increment_rates_saving'][i] is not None else '-'
300
301
            col = chr(ord(col) + 1)
302
303
        ws[col + str(current_row_number)].font = name_font
304
        ws[col + str(current_row_number)].alignment = c_c_alignment
305
        ws[col + str(current_row_number)].border = f_border
306
        ws[col + str(current_row_number)] = str(
307
            round(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \
308
            if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-'
309
310
        col = chr(ord(col) + 1)
311
312
        ws[col + str(current_row_number)].font = name_font
313
        ws[col + str(current_row_number)].alignment = c_c_alignment
314
        ws[col + str(current_row_number)].border = f_border
315
        ws[col + str(current_row_number)] = str(
316
            round(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \
317
            if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-'
318
319
        col = chr(ord(col) + 1)
320
321
        current_row_number += 2
322
323
        ws['B' + str(current_row_number)].font = title_font
324
        ws['B' + str(current_row_number)] = name + ' 吨标准煤(TCE)占比'
325
326
        current_row_number += 1
327
        table_start_row_number = current_row_number
328
        chart_start_row_number = current_row_number
329
330
        ws.row_dimensions[current_row_number].height = 60
331
        ws['B' + str(current_row_number)].fill = table_fill
332
        ws['B' + str(current_row_number)].border = f_border
333
334
        ws['C' + str(current_row_number)].fill = table_fill
335
        ws['C' + str(current_row_number)].font = name_font
336
        ws['C' + str(current_row_number)].alignment = c_c_alignment
337
        ws['C' + str(current_row_number)].border = f_border
338
        ws['C' + str(current_row_number)] = '吨标准煤(TCE)占比'
339
340
        current_row_number += 1
341
342
        for i in range(0, ca_len):
343
            ws['B' + str(current_row_number)].font = title_font
344
            ws['B' + str(current_row_number)].alignment = c_c_alignment
345
            ws['B' + str(current_row_number)].border = f_border
346
            ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
347
348
            ws['C' + str(current_row_number)].font = name_font
349
            ws['C' + str(current_row_number)].alignment = c_c_alignment
350
            ws['C' + str(current_row_number)].border = f_border
351
            ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
352
353
            current_row_number += 1
354
355
        table_end_row_number = current_row_number - 1
356
357
        if ca_len < 4:
358
            current_row_number = current_row_number - ca_len + 4
359
360
        current_row_number += 1
361
362
        pie = PieChart()
363
        pie.title = name + ' 吨标准煤(TCE)占比'
364
        labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
365
        pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
366
        pie.add_data(pie_data, titles_from_data=True)
367
        pie.set_categories(labels)
368
        pie.height = 7.25
369
        pie.width = 9
370
        s1 = pie.series[0]
371
        s1.dLbls = DataLabelList()
372
        s1.dLbls.showCatName = False
373
        s1.dLbls.showVal = True
374
        s1.dLbls.showPercent = True
375
        ws.add_chart(pie, 'D' + str(chart_start_row_number))
376
377
        ws['B' + str(current_row_number)].font = title_font
378
        ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
379
380
        current_row_number += 1
381
        table_start_row_number = current_row_number
382
        chart_start_row_number = current_row_number
383
384
        ws.row_dimensions[current_row_number].height = 60
385
        ws['B' + str(current_row_number)].fill = table_fill
386
        ws['B' + str(current_row_number)].border = f_border
387
388
        ws['C' + str(current_row_number)].fill = table_fill
389
        ws['C' + str(current_row_number)].font = name_font
390
        ws['C' + str(current_row_number)].alignment = c_c_alignment
391
        ws['C' + str(current_row_number)].border = f_border
392
        ws['C' + str(current_row_number)] = '吨二氧化碳排放(TCO2E)占比'
393
394
        current_row_number += 1
395
396
        for i in range(0, ca_len):
397
            ws['B' + str(current_row_number)].font = title_font
398
            ws['B' + str(current_row_number)].alignment = c_c_alignment
399
            ws['B' + str(current_row_number)].border = f_border
400
            ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
401
402
            ws['C' + str(current_row_number)].font = name_font
403
            ws['C' + str(current_row_number)].alignment = c_c_alignment
404
            ws['C' + str(current_row_number)].border = f_border
405
            ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
406
407
            current_row_number += 1
408
409
        table_end_row_number = current_row_number - 1
410
411
        if ca_len < 4:
412
            current_row_number = current_row_number - ca_len + 4
413
414
        current_row_number += 1
415
416
        pie = PieChart()
417
        pie.title = name + ' 吨二氧化碳排放(TCO2E)占比'
418
        labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
419
        pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
420
        pie.add_data(pie_data, titles_from_data=True)
421
        pie.set_categories(labels)
422
        pie.height = 7.25
423
        pie.width = 9
424
        s1 = pie.series[0]
425
        s1.dLbls = DataLabelList()
426
        s1.dLbls.showCatName = False
427
        s1.dLbls.showVal = True
428
        s1.dLbls.showPercent = True
429
        ws.add_chart(pie, 'D' + str(chart_start_row_number))
430
431
    #############################################
432