'How to automatically display a specific range of columns on a spreadsheet created with xlsxwriter?

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?

enter image description here



Solution 1:[1]

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:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jmcnamara