我正在尝试使用 PhpSpreadSheet 从.xlsx
文件中读取一些单元格值,但是我不知道为什么这不起作用。该文件打开,但是当我读取单元格的值时,它什么也不返回。我检查了文件名是否正确以及单元格是否有数据。我想阅读文件的 SECOND 表,这就是为什么我使用getSheet(1)
的原因。
这是我的代码:
use PhpOffice\PhpSpreadsheet\IOFactory;
$inputFileType = 'Xlsx';
$inputFileName = 'Test.xlsx';
$reader = IOFactory::createReader($inputFileType);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName);
$sheet = $spreadsheet->getSheet(1);
$filterHours = $sheet->getCell('D309')->getOldCalculatedValue();
$otherHour = $sheet->getCell('D295')->getOldCalculatedValue();
$title = $sheet->getCell('B297')->getOldCalculatedValue();
printf($title);
printf($filterHours);
printf($otherHour);
编辑:如果我使用getCalculatedValue()
而不是getOldCalculatedValue()
,则会出现此错误:
致命错误:未捕获的PhpOffice \ PhpSpreadsheet \ Calculation \ Exception:
Configurador!D309-> Configurador!D745-> Configurador!D755-> Configurador!C776-> 公式错误:发生意外错误 C:\ xampp \ htdocs \ OfferConfigurator \ vendor \ phpoffice \ phpspreadsheet \ src \ PhpSpreadsheet \ Cell \ Cell.php:274
堆栈跟踪:#0 C:\ xampp \ htdocs \ OfferConfigurator \ php \ generateDocumentation \ prueba.php(26): PhpOffice \ PhpSpreadsheet \ Cell \ Cell-> getCalculatedValue()
#1 {main}投入 C:\ xampp \ htdocs \ OfferConfigurator \ vendor \ phpoffice \ phpspreadsheet \ src \ PhpSpreadsheet \ Cell \ Cell.php 在第274行
那是因为Configurador!C776
的公式引用了另一张纸吗?
答案 0 :(得分:-1)
尝试将您的Phpspreadsheet版本降级为1.8.2。