Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel How to de-select column or range after setting a style

Tags:

php

phpexcel

I have this code in my action page, which centers text in a range in the J column of my active worksheet:

$objPHPExcel->setActiveSheetIndex(0);

$lastrow = $objPHPExcel->getActiveSheet()->getHighestRow();

$objPHPExcel->getActiveSheet()
            ->getStyle('J1:J'.$lastrow)
            ->getAlignment()
            ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

This works fine, except that when I trigger the opening of MS Excel, and it opens the worksheet, the entire J column is highlighted. What I want is for the client to open the spreadsheet, but not have any columns or cells highlighted or selected.

like image 528
TARKUS Avatar asked Jan 23 '26 18:01

TARKUS


1 Answers

I do not know how to unselect all cells, but you can select the cell A1, which is the top left cell. That will give the appearance of "no cell selected" and will open the sheet scrolled to the top and left. The function call is simple:

setSelectedCells('A1')
like image 186
kainaw Avatar answered Jan 26 '26 09:01

kainaw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!