Python 2.7:
我正在使用 XlsxWriter 提供的 set_border(1)
函数为 Excel 文件中的所有单元格设置边框。但是,它不会为空单元格添加底部边框。我如何确保这些单元格也有边框?
import xlrd
import xlsxwriter
file_path = "/desktop/first_sheet.xlsx"
[![enter image description here][1]][1]
old_wb = xlrd.open_workbook(file_path)
old_ws = old_wb.sheet_by_name("tables")
all_rows = []
for row in range(old_ws.nrows):
curr_row = []
for col in range(old_ws.ncols):
curr_row.append(old_ws.cell_value(row, col))
all_rows.append(curr_row)
new_file = file_path + "_tables.xlsx"
new_wb = xlsxwriter.Workbook(new_file)
new_ws = new_wb.add_worksheet()
for row in range(len(all_rows)):
for col in range(len(all_rows[0])):
new_ws.write(row, col, all_rows[row][col])
cell_format.set_border(1)
cell_format.set_font_name('Times New Roman')
cell_format.set_font_size(9)
cell_format.set_text_wrap()
new_ws.set_column('B1:B9999', 4.91)
new_ws.set_column('C1:C9999', 8.09)
new_ws.set_column('D1:D9999', 8.55)
new_ws.set_column('E1:E9999', 23.82)
new_ws.set_column('F1:F9999', 6.18)
new_ws.set_column('G1:G9999', 7.18)
new_ws.set_column('H1:H9999', 15.64)
new_ws.set_column('A:Z', None, cell_format)
header_format = new_wb.add_format({'bold': True})
header_list = ["Issue", "Type", "Status", "Resolution", "Summary", "Priority", "Fix Version", "Labels"]
for value in header_list:
new_ws.conditional_format('A1:Z9999', {'type': 'cell', 'criteria': 'equal to', 'value': '"%s"' % value , 'format': header_format})
new_wb.close()