0

That's a simple question.

I'm building a PHP Excel from scratch and is a very useful package. I need to catch the active cell or row to know which cells to modify and customize, I checked all methods in the package and I didn't found something that helped me. I'm inserting some data like this:

$sheet->appendRow(array(
                $variable->value1,
                $variable->value2,
                $variable->value3,
            ));

And then I want to customize some things(This example I'm changing the background color), something like:

//The XXX is the last active row that I append some value before
$sheet->cells('XXXX',function ($cells){
                $cells->setBackground('#34EC34');
            });

There's some way to do find out the active cell or row to put in place of the 'XXX'? I found some question on Stack that someone was accessing by the variable $row, but I didn't found how to access....

Community
  • 1
  • 1
Deric Lima
  • 1,972
  • 2
  • 24
  • 33

2 Answers2

0
  1. go to class name "LaravelExcelWorksheet" in vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php

  2. Try to change method modifier of getStartRow from protected to public

  3. You can use it with $sheet->getStartRow(), that's show you active row
Kaew
  • 11
  • 3
0

Kaew's answer works, but to do this without modifying then LaravelExcel source, you can just use the method that getStartRow() uses internally - getHighestRow() - and add to the returned value if needed.

Here is the Laravel Excel 2.1 source for the getStartRow() method.

Robb
  • 1