ajay
ajay

Reputation: 31

set no of rows and columns xlsxwriter python

I am trying to set specific no of rows & columns for particular worksheet (incident_sheet3) Tried set_row/set_column and 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)

Used set_column to set width for cells in defined range

Upvotes: 1

Views: 2936

Answers (1)

jmcnamara
jmcnamara

Reputation: 41644

The syntax for set_column() is:

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

In your example you don't specify a width:

incident_sheet3.set_column(0,1)

Update: If you are trying to display a certain area of the worksheet and to hide everything else you can do it like this:

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

Output:

enter image description here

See the example in the XlsxWriter docs.

Upvotes: 0

Related Questions