xlsxwriter:如何在具有合并行的列中创建“色阶”?

时间:2019-02-25 12:36:45

标签: python excel colors xlsxwriter python-3.7

enter image description here

(我通常只是用英语阅读,对不起,写错了)

我希望将public class NumWatcher implements TextWatcher { private EditText editText; private int selPos; private String oldString, newString; public NumWatcher(EditText editText) { this.editText = editText; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { selPos = editText.getSelectionStart(); oldString = myFilter(s.toString()); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { editText.removeTextChangedListener(this); newString = myFilter(s.toString()); editText.setText(newString); int newPos = selPos + (newString.length() - oldString.length()); if (newPos < 0) newPos = 0; editText.setSelection(newPos); editText.addTextChangedListener(this); } public String myFilter(String s) { String digits; digits = s.replaceAll("[^0-9]", ""); if (s.equals("")) return ""; return digits; } } 绘制为column C,合并的两行具有相同的颜色。 我如何合并和格式化column A

column A

但是我不确定如何使用def mergeRows(worksheet, first_row, col, how_many, rows_to_merge=2, value=None, format=None): if type(value) in (int, str) or value is None: [worksheet.merge_range(row, col, row + rows_to_merge - 1, col, value, format) for row in range(first_row, ((how_many * rows_to_merge) + first_row), rows_to_merge)] else: [worksheet.merge_range(row, col, row + rows_to_merge - 1, col, value[i], format) for i, row in enumerate(range(first_row, ((how_many * rows_to_merge) + first_row), rows_to_merge))] row = 4 mergeRows(worksheet, first_row=row+1, col=0, how_many=d['n_sensors'], value=list(range(d['n_sensors'])), format=formats['sensor']) mergeRows(worksheet, first_row=row+1, col=1, how_many=d['n_sensors'], format=formats['column']) mergeRows(worksheet, first_row=row+1, col=2, how_many=d['n_sensors'], format=formats['column']) worksheet.conditional_format(row + 1, 0, row + 1 + d['n_sensors'] * 2, 0, {'type': 'formula', 'criteria': '=MOD(ROW(),4) = 0', # format if the row number % 4 == 0. 'format': formats['sensor_blue']}) 来实现,因为color scale中的column A中使用的相同条件不适用于color scale中的column C

worksheet.conditional_format(row+1, 2, row +1 +(d['n_sensors']*2), 2, {'type': '3_color_scale',
                                                                     'min_color': 'green',
                                                                     'mid_color': 'yellow',
                                                                     'max_color': 'red',
                                                                     'criteria': '=MOD(ROW(),4) = 0'})

代码:

    for sensor, samples in enumerate(x_test):

        ############################### Classifica e preenche os valores de cada sensor ###############################
        y = model.predict(samples)
        n_outliers = 0
        if samples.shape[1] == 2:
            for group in range(0, len(y)):
                if y[group] == 1:
                    worksheet.write(row + 1 + sensor*2, group + 5, samples[group][0],  formats['pp_approved'])
                    worksheet.write(row + 2 + sensor*2, group + 5, samples[group][1],  formats['std_approved'])
                else:
                    n_outliers += 1
                    worksheet.write(row + 1 + sensor*2, group + 5, samples[group][0], formats['pp_reproved'])
                    worksheet.write(row + 2 + sensor*2, group + 5, samples[group][1], formats['std_reproved'])

                worksheet.write_comment(row + 1 + sensor*2, group + 5,
                                    "         CANAL {}\n\n{}\n\n{}".format(sensor,
                                                                        convertTime(groups_time[0, group], timezone.utc).strftime("%Y.%m.%d %H:%M:%S.%f")[:-3],
                                                                        convertTime(groups_time[1, group], timezone.utc).strftime("%Y.%m.%d %H:%M:%S.%f")[:-3]))
                                                                                            #TODO Corrigir o tempo.

        ############################################## Coluna de Alerta ##############################################
        if n_outliers < args.alert:
            n_approv += 1

        worksheet.write(row + 1 + sensor*2, 2, n_outliers)

    worksheet.conditional_format(row+1, 2, row +1 +(d['n_sensors']*2), 2, {'type': '3_color_scale',
                                                                     'min_color': 'green',
                                                                     'mid_color': 'yellow',
                                                                     'max_color': 'red',
                                                                     'criteria': '=MOD(ROW(),4) = 0'})

0 个答案:

没有答案