我一直在创建几个公式并将它们添加到PhpSpreadsheet中,没有任何问题。但是,当我创建以下公式时,将其添加到PhpSpreadsheet中并打开xlsx文件,这8行中的6行具有'#VALUE!'
该公式正在计算大于或等于最小值且小于或等于最大值的单元格范围的STDEV。
公式是这样创建的:
$cf_mP_Stdev =
"=STDEV(IF(('" . $samplesWellsSheetName . "'!" . $mpCol . ($writeSampleWellsRow - 319) . ":" . $mpCol . $writeSampleWellsRow . ">=J" . $writeControlPlatesRow . ")*('" .
$samplesWellsSheetName . "'!" . $mpCol . ($writeSampleWellsRow - 319) . ":" . $mpCol . $writeSampleWellsRow . "<=L" . $writeControlPlatesRow . "),'" .
$samplesWellsSheetName . "'!" . $mpCol . ($writeSampleWellsRow - 319) . ":" . $mpCol . $writeSampleWellsRow . "))";
在Excel中,我期望是:
=STDEV(IF(('Samples-Wells'!H3:H322>=J4)*('Samples-Wells'!H3:H322<=L4),'Samples-Wells'!H3:H322))
但是当我打开xlsx文件时,在三个范围中的两个范围前面有'@'符号:
=STDEV(IF((@'Samples-Wells'!H3:H322>=J4)*(@'Samples-Wells'!H3:H322<=L4),'Samples-Wells'!H3:H322))
对于该公式和下一个公式,计算得出的值是正确的。但是对于接下来的6个公式,我收到了“ #VALUE!”。这是第三个公式。没有区别,只是针对下一组单元格。 Samples-Wells工作表中的H列具有从第3行到1282行的数据。
=STDEV(IF((@'Samples-Wells'!H323:H642 >= J6)*(@'Samples-Wells'!H323:H642 <= L6),'Samples-Wells'!H323:H642))
所以我的问题是:
为什么将@符号添加到公式中?这是来自PhpSpreadsheet还是Excel?
侧面注:如果我从Excel中的公式中手动删除@符号,然后按Enter键,则计算正确。
关于“ Stdev mP”的前两个公式为何起作用但后六个失败的任何想法?
使用PhpSpreadsheet 1.10.1
@用于数字/文本格式,作为字符串,也许问题出在这部分。我将在设置值时调试进入公式器,如果公式中为@ remove
var_dump($formula);
str_replace("@", "", $formula);
$spreadsheet->getActiveSheet()->setCellValue('A2', $formula);
找到了如何通过此StackOverflow链接为数组公式编写代码:
https://stackoverflow.com/a/59930320/5359251
$attrs = $sheet->getCell("C1")->getFormulaAttributes();
$attrs['t'] = 'array';
$sheet->getCell("C1")->setFormulaAttributes($attrs);
我在PhpSpreadsheet文档中找不到任何东西。