简体   繁体   中英

How do you read a file with formulas in phpspreadsheet?

I have the following code:

$Reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$Reader->setReadDataOnly( true );
try {
   $spreadSheet = $Reader->load( $file );
} catch (\Exception $e) {
   echo json_encode( $e->getMessage() );
   exit;
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
   echo json_encode( $e->getMessage() );
   exit;
}

$excelSheet = $spreadSheet->getActiveSheet();
$spreadSheetAry = $excelSheet->toArray();
$maxCell = $excelSheet->getHighestRowAndColumn();
$data = $excelSheet->rangeToArray( 'A1:' . $maxCell['column'] . $maxCell['row'] );
$data = array_map( 'array_filter', $data );
$data = array_filter( $data );

which works fine, if it is file that contains no formulas. But if I try to read a file that contains formulas, I get the following error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67108872 bytes) in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php on line 395

My question is, how can I get phpspreadsheet to either ignore or calculate the formulas inside the file? The error occurs in $Reader->load( $file ); while trying to read it, so i'm not able to get back any data from the file.

Any help would be greatly appreciated!

$Reader->setReadDataOnly( true );

says read only the data and that you can't use the calculation more information see here.

Remove above line or set it to false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM