首页 > 解决方案 > 如何从 Laravel excel 2.1 获取具有单元格地址的所有单元格值?

问题描述

我正在尝试读取一个 excel 文件并获取所有带有单元格地址的单元格值。我在文档中找不到任何东西。( https://laravel-excel.maatwebsite.nl/2.1/getting-started/ )

标签: phplaravel

解决方案


我不知道如何使用 maatwebsite 库来做到这一点,但如果你想直接获取带有地址的单元格,我认为这个库能够做到这一点https://phpspreadsheet.readthedocs.io/en/develop/topics/访问细胞/

// Get the value from cell A1
$cellValue = $spreadsheet->getActiveSheet()->getCell('A1')->getValue();

* 编辑

$rowMax = 5;
$columnMax = 'E';
$result = [];

for ($i = 1; $i <= $rowMax; $i++) {
    for ($j = 1; $j <= \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($columnMax); $j++) {
        $cellName = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($j) . $i;
        $result[$cellName] = $sheet->getCell($cellName)->getValue()
    }
}

推荐阅读