设置行和列xlsxwriter python没有

时间:2016-11-25 19:50:41

标签: excel python-3.x xlsxwriter

我正在尝试设置特定的行数和行数特定工作表的列(incident_sheet3) 尝试了set_row / set_column和set_size

incident_excel_file = xlsxwriter.Workbook("incidents_excel.xlsx")
incident_sheet = incident_excel_file.add_worksheet(name="incidents")
incident_sheet2 = incident_excel_file.add_worksheet(name="Handoff Template")
incident_excel_file.set_size(100,100)
incident_sheet.set_column(0,4,25)
incident_sheet2.set_column(0,15,15)
incident_sheet3 = incident_excel_file.add_worksheet()
incident_sheet3.set_column(0,1)

使用set_column为定义范围内的单元格设置宽度

1 个答案:

答案 0 :(得分:0)

set_column()的语法是:

set_column(first_col, last_col, width, cell_format, options)

在您的示例中,您没有指定宽度:

incident_sheet3.set_column(0,1)

更新:如果您尝试显示工作表的某个区域并隐藏其他所有内容,可以这样做:

import xlsxwriter

workbook = xlsxwriter.Workbook('hide_row_col.xlsx')
worksheet = workbook.add_worksheet()

# Write some data.
worksheet.write('D1', 'Some hidden columns.')
worksheet.write('A8', 'Some hidden rows.')

# Hide all rows without data.
worksheet.set_default_row(hide_unused_rows=True)

# Set the height of empty rows that we do want to display even if it is
# the default height.
for row in range(1, 7):
    worksheet.set_row(row, 15)

# Columns can be hidden explicitly. This doesn't increase the file size.
worksheet.set_column('G:XFD', None, None, {'hidden': True})

workbook.close()

输出:

enter image description here

请参阅XlsxWriter文档中的example