How to freeze entire header row in openpyxl? So far I can only freeze the column:
# only freeze the column (freeze vertically) cell = ws.cell('{}{}'.format(col, row_idx+1)) worksheet.freeze_panes = cell
Have a look here, scroll down to the heading Writing Values to Cells. TLDR: >>> import openpyxl >>> wb = openpyxl. Workbook() >>> sheet = wb['Sheet'] >>> sheet['A1'] = 'Hello world!
Make sure cell
isn't on row one - freeze_panes
will freeze rows above the given cell and columns to the left.
from openpyxl import Workbook wb = Workbook() ws = wb.active c = ws['B2'] ws.freeze_panes = c wb.save('test.xlsx')
This will give you a blank worksheet with both row 1 and column A frozen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With