I would like to automatically display a specific range of columns when opening an excel spreadsheet created with xlsxwriter.
This is illustrated in the example below where the first row and column are frozen while the range of columns being displayed start at E
and not at B
(but note that I don’t want B:D
to be hidden, I just want to start the range of column displayed at E
)
Is this doable?
Advertisement
Answer
The XlsxWriter worksheet.freeze_panes()
method has 2 optional parameters (top_row
, left_column
) which can be used to set the first cell in the non-frozen area. Like this:
import xlsxwriter workbook = xlsxwriter.Workbook('panes.xlsx') worksheet = workbook.add_worksheet() side_format = workbook.add_format({'bold': True, 'fg_color': '#D7E4BC', 'border': 1}) worksheet.freeze_panes(0, 1, 0, 4) # Some sample data. for row_num in range(0, 50): worksheet.write(row_num, 0, 'Frozen', side_format) for col_num in range(1, 26): worksheet.write(row_num, col_num, row_num + 1) workbook.close()
Output: