【问题标题】:PHPSpreadsheet: how to get the number of loaded rows?PHPSpreadsheet:如何获取加载的行数?
【发布时间】:2018-07-25 04:22:46
【问题描述】:

如何知道我使用PHPSpreadsheet\Reader\Xlsx::load() 方法加载了多少行?

我也找不到在电子表格或工作表类中获取行数的方法(或属性)。

顺便说一句,我正在使用以下代码:

$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();

【问题讨论】:

    标签: php excel phpspreadsheet


    【解决方案1】:

    使用工作表的getHighestRow() 方法

    $highestRow = $this->spreadsheet->getActiveSheet()->getHighestRow();
    

    或getHighestDataRow(),如果您只对单元格包含数据的行感兴趣,而不是工作表末尾的任何空白行

    【讨论】:

    • 注意:对于列,它们有一个类似但不是很直观的命名方法getHighestColumn
    • 这给出了列索引,例如 AJ 计数呢?
    • @NixonKosgei - 然后使用 Coordinate columnIndexFromString() 方法将 AJ 转换为其等效数字
    猜你喜欢
    • 2021-03-06
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 2020-10-19
    • 2023-02-07
    • 2017-02-05
    • 2019-10-01
    • 2020-02-01
    相关资源
    最近更新 更多