PhpSpreadsheet:SUMIF公式不起作用

时间:2019-03-03 13:56:19

标签: php excel sumifs phpspreadsheet

预期的行为是什么?

我尝试添加公式= SUMIF,但这不起作用。打开Excel文件时发生错误,公式被删除

当前行为是什么?

当代码尝试计算公式时,这很麻烦

要复制的步骤是什么?

sumif.xlsx:检查此页面:https://github.com/PHPOffice/PhpSpreadsheet/issues/892以下载xlsx

<?php require 'vendor/autoload.php';

set_time_limit(-1);
//error_reporting(0);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
$objPHPExcel = $reader->load("sumif.xlsx");
$objPHPExcel->setActiveSheetIndex(1);

for($count = 1 ; $count <= 10; $count++)
{
    $objPHPExcel->getActiveSheet()->setCellValue('D'.$count, '=SUMIF(Résumé!D$2:D$22;B'.$count.';Résumé!F$2:F$22)');
}

$objPHPExcel->setActiveSheetIndex(0);

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="paiement_'.date('Y-m-d').'.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
/**/
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($objPHPExcel);
$objWriter->setPreCalculateFormulas(false);
$objWriter->save('php://output');
/**/
?>

PhpSpreadsheet和PHP的哪个版本受到影响?

PHP 7.0和PhpSpreadsheet 1.6.0

1 个答案:

答案 0 :(得分:0)

在公式字符串上,尝试像这样使用,而不是;

'=SUMIF(Résumé!D$2:D$22,B'.$count.',Résumé!F$2:F$22)'