VLOOKUP在PHPSpreadsheet中返回#N / A

时间:2018-12-14 08:27:24

标签: php wordpress phpspreadsheet

我正在尝试使用在phpspreadsheet的excel文件中实现的计算器。处理多张纸。第一张纸本身就有计算器。

我将价值观正确地放入其中吗?

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('calc.xlsx');
$worksheet = $spreadsheet->setActiveSheetIndex(0);
$worksheet->setCellValue('D8', 210000);
$worksheet->setCellValue('D9', 160000);
$worksheet->setCellValue('D10', '5%');
$worksheet->setCellValue('D11', 30);
$worksheet->setCellValue('D12', -1073);
$worksheet->setCellValue('D15', 50000);
$worksheet->setCellValue('D16', '7%');
$worksheet->setCellValue('D19', 5000);
$worksheet->setCellValue('D20', 5000);
$worksheet->setCellValue('D21', 4500);
$worksheet->setCellValue('D24', '12/7/2018');

因为下面的代码输出#N / A

$worksheet->setCellValue('I8', '=VLOOKUP("L",Daily!A:N,3,FALSE)');
echo $worksheet->getCell('I8')->getFormattedValue();

尝试在wrdpress插件中执行此操作。

2 个答案:

答案 0 :(得分:0)

您的VLOOKUP公式中名为“每日”的工作表上是什么?我使用了相同的代码,并且在工作表1上生成了以下代码:

Sheet1

出于测试目的,我还把“日常”表中的内容包括在内。

Daily

$path = 'c:/xxx/xxx/desktop/TestDoc.xlsx';

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path);
$worksheet = $spreadsheet->setActiveSheetIndex(0);
$worksheet->setCellValue('D8', 210000);
$worksheet->setCellValue('D9', 160000);
$worksheet->setCellValue('D10', '5%');
$worksheet->setCellValue('D11', 30);
$worksheet->setCellValue('D12', -1073);
$worksheet->setCellValue('D15', 50000);
$worksheet->setCellValue('D16', '7%');
$worksheet->setCellValue('D19', 5000);
$worksheet->setCellValue('D20', 5000);
$worksheet->setCellValue('D21', 4500);
$worksheet->setCellValue('D24', '12/7/2018');
$worksheet->setCellValue('I8', '=VLOOKUP("L",Daily!A:N,3,FALSE)');
echo $worksheet->getCell('I8')->getFormattedValue();
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
$writer->save('c:/xxx/xxx/desktop/TestDoc.xlsx');

答案 1 :(得分:0)

我的 Excel 非常复杂,我也遇到了同样的问题。 经过数小时的谷歌搜索和研发,我通过将工作表名称与单元格一起传递来解决了这个问题。

引起我问题的公式是: =VLOOKUP(B3,'Resort'!D5:L185,9)

解决问题的 V-Lookup 公式是: =VLOOKUP('Sheet1'!B3,'Resort'!D5:L185,9)