php - 如何从 Laravel excel 2.1 获取具有单元格地址的所有单元格值?
问题描述
我正在尝试读取一个 excel 文件并获取所有带有单元格地址的单元格值。我在文档中找不到任何东西。( https://laravel-excel.maatwebsite.nl/2.1/getting-started/ )
解决方案
我不知道如何使用 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()
}
}
推荐阅读
- javascript - 在 package.json 中设置启动脚本
- python - VS Code jupyter notebook matplotlib 直接在绘图查看器中绘图?
- javascript - React:从类到函数的异步
- javascript - vue:使用可选参数将 2 个方法重构为 1 个方法?
- github - 如何将 github 赞助商按钮添加到自述文件
- python - 为点和多边形的大量集合有效地匹配点到几何(多边形中的点)
- r - 如何计算涉及日期时间的特定条件的事件
- sql - 将 varchar 数据类型转换为 datetime 数据类型的问题导致值超出范围
- javascript - 包含失败的过滤器数组
- javascript - 如何防止 ForEach 同时运行所有网络请求?