How do I find out how many rows I have loaded using PHPSpreadsheet\Reader\Xlsx::load()
method?
I cannot find methods (or properties) for getting row count in Spreadsheet or Worksheet classes either.
BTW I am using following code:
$filename = 'test.xlsx';
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($filename);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$reader->setReadDataOnly(true);
$reader->setLoadSheetsOnly($sheet);
$this->spreadsheet = $reader->load($filename);
$this->worksheet = $this->spreadsheet->getActiveSheet();
$objPHPExcel->setActiveSheetIndex(0)->getHighestDataRow(); Use the getHighestDataRow() method to get the highest row number for cells that have actual content.
To retrieve the value of a cell, the cell should first be retrieved from the worksheet using the getCell() method. A cell's value can be read using the getValue() method. // Get the value from cell A1 $cellValue = $spreadsheet->getActiveSheet()->getCell('A1')->getValue();
PhpSpreadsheet is a library written in pure PHP and offers a set of classes that allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.
Use composer to install PhpSpreadsheet into your project. Or also download the documentation and samples if you plan to use them. A good way to get started is to run some of the samples. Don't forget to download them via --prefer-source composer flag.
Using the worksheet's getHighestRow()
method
$highestRow = $this->spreadsheet->getActiveSheet()->getHighestRow();
or getHighestDataRow()
if you're only interested in rows where cells contain data and not any blank rows at the end of the worksheet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With