Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to freeze headers and a set of columns using PHPExcel

Tags:

php

phpexcel

I want to freeze my page headers and columns like so:

enter image description here

I can freeze my headers absolutely fine and dandy:

    $highestRowCount = $sheet->getHighestRow();
    $highestColumnCount = $sheet->getHighestColumn();

    $sheet->freezePane( "{$highestColumnCount}2" );

But when I then add another freeze on the columns:

    $sheet->freezePane( "D{$highestRowCount}" );

It breaks excels ability to scroll...

How might I go about doing this?

like image 636
Jimmyt1988 Avatar asked Jul 03 '14 11:07

Jimmyt1988


1 Answers

Freeze fourth column and first line :

$sheet = $spreadsheet->getActiveSheet(); //get current active sheet (first sheet)

$sheet->freezePane('D2');

And if you want to Freeze first column and first line:

$sheet->freezePane('B2');

Freeze first column only:

$sheet->freezePane('B1');

Freeze till second column:

$sheet->freezePane('C1');

Freeze first line(row) Only:

$sheet->freezePane('A2');

Freeze til second line(row):

$sheet->freezePane('A3');
like image 192
Irshad Khan Avatar answered Sep 18 '22 06:09

Irshad Khan