设置行数和列数 xlsxwriter python

set no of rows and columns xlsxwriter python

我正在尝试为特定工作表设置特定的行数和列数 (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 设置定义范围内单元格的宽度

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()

输出:

请参阅 XlsxWriter 文档中的 example