1

A) I would like to have a PHPExcel-generated file to open with cell A1 selected. Not a problem: I can do that.

B) I would like to have a PHPExcel-generated file with frozen panes (at 'E6', but that's not the real issue). Again, not a problem: I can do that.

Now, when trying to do A and B, that's when I hit a real problem: the file always opens with cell E6 selected, no matter what I try...

I've tried using $objPHPExcel->getActiveSheet()->freezePane('E6'); in different stages of the file construction (right at the beginning, at the end, in the middle), always with $objPHPExcel->getActiveSheet()->setSelectedCell('A1'); AFTER freezing the panes, but no luck...

I searched and searched and found no solution to this (except a perhaps-related-but-unanswered request here at SO). Either I'm overlooking something obviously simple or I've uncovered a small bug... :-) Can someone help?

Many thanks in anticipation.

Paulo_M_
  • 23
  • 5
  • Unable to replicate! I freeze the pane, then I setSelectedCell('A1') and no problems..... what format are you writing to? – Mark Baker Nov 23 '15 at 22:20
  • xlsx... I'm puzzled. I agree that it should be a straightforward thing, yet I keep running into the same issue again and again. It's a moderately complex page and I wonder if it's some other issue that's interfering. Tomorrow I'll write sample (and simple) file and report back here. Thanks for the feedback! – Paulo_M_ Nov 23 '15 at 23:30
  • @mark-baker I was about to "report back here", after making different attempts and always coming up with the same reproducible scenario (the selected cell *never* goes to A1). I then saw your reply and will now see how the fix works. Thanks again for the feedback. – Paulo_M_ Nov 24 '15 at 16:21

1 Answers1

0

Looking at the code, The Excel2007 Writer overrides the selected cell when there's a split pane, changing it to the top-left cell of the split.

Quick and dirty fix in Classes/PHPExcel/Writer/Excel2007/Worksheet.php, change line 262 which should read

$activeCell = $topLeftCell;

to

$activeCell = empty($activeCell) ? $topLeftCell : $activeCell;

I haven't tested it fully, but it should work for now.... I really should be testing to see which "pane" the selected cell falls into, and setting appropriately in that pane

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • The "quick and dirty fix" appears to work fine in a test file. Based on what I'm doing, I expect it to be a suitable solution. Thank you for the helpful feedback. I'll be using the "patch" from now on and if I don't report back here it means that all is well... Thanks again! – Paulo_M_ Nov 24 '15 at 16:32