35 Votes

PHPExcel: Freeze first Line and Column

Question by PC Control | 2015-03-22 at 19:05

I am using PHPExcel to be able to offer an Excel export on my website with the help of PHP.

Now I would like to fix the first column and line of my Excel spreadsheet (I think that is called freezing).

Does PHPExcel support this function? Is it possible to freeze columns and/or lines with PHPExcel?

ReplyPositiveNegativeDateVotes
4Best Answer6 Votes

Yes, PHPExcel is providing the function freezePane() with which you can selectively freeze lines, columns or both. khaki are some examples:

Freezing Lines

Freeze first line:

$objPHPExcel->getActiveSheet()->freezePane('A2');

Freeze second line:

$objPHPExcel->getActiveSheet()->freezePane('A3');

Freezing Columns

Freeze first column:

$objPHPExcel->getActiveSheet()->freezePane('B1');

Freeze second column:

$objPHPExcel->getActiveSheet()->freezePane('C1');

Freezing Columns and Lines

Freeze first column and first line:

$objPHPExcel->getActiveSheet()->freezePane('B2');

Freeze fourth column and first line:

$objPHPExcel->getActiveSheet()->freezePane('D2');

As you can see, we are passing the cell before that it should be freezed. In order to only freeze lines, you have to keep the column at "A" and in order to freeze columns, accordingly, you have to keep the line at "1". When combining this, you get the corresponding cell beyond "A" and "1".
2015-03-23 at 13:42

ReplyPositive Negative
02 Votes

Thanks for your example on phpExcel, very helpful, this is what I looking for my current project, :)

For my project I used this:

$objPHPExcel->getActiveSheet()->freezePane("B8");

for my customized reporting format.
2017-03-27 at 07:41

Positive Negative
Reply
Reply

Related Topics

Quicksort: Sort two Columns

Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.