Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to freeze entire header row in openpyxl?

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 
like image 983
Yudhistira Arya Avatar asked Aug 31 '14 04:08

Yudhistira Arya


People also ask

How do I create a row in openpyxl?

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!


1 Answers

Make sure cell isn't on row one - freeze_panes will freeze rows above the given cell and columns to the left.


Example:

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.

like image 163
user3942918 Avatar answered Sep 24 '22 03:09

user3942918