@aubaub当前的解决方案绘制了一个空框。我需要在现有值周围画一个框架,而不覆盖它们。这是我的职责,以防对任何人有帮助:def draw_frame_border(workbook, worksheet, first_row, first_col, rows_count, cols_count):
# top left corner
worksheet.conditional_format(first_row, first_col,
first_row, first_col,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'top': 1, 'left': 1})})
# top right corner
worksheet.conditional_format(first_row, first_col + cols_count - 1,
first_row, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'top': 1, 'right': 1})})
# bottom left corner
worksheet.conditional_format(first_row + rows_count - 1, first_col,
first_row + rows_count - 1, first_col,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'bottom': 1, 'left': 1})})
# bottom right corner
worksheet.conditional_format(first_row + rows_count - 1, first_col + cols_count - 1,
first_row + rows_count - 1, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'bottom': 1, 'right': 1})})
# top
worksheet.conditional_format(first_row, first_col + 1,
first_row, first_col + cols_count - 2,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'top': 1})})
# left
worksheet.conditional_format(first_row + 1, first_col,
first_row + rows_count - 2, first_col,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'left': 1})})
# bottom
worksheet.conditional_format(first_row + rows_count - 1, first_col + 1,
first_row + rows_count - 1, first_col + cols_count - 2,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'bottom': 1})})
# right
worksheet.conditional_format(first_row + 1, first_col + cols_count - 1,
first_row + rows_count - 2, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'right': 1})})