设置行数和列数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文档中的示例 。