连接到Excel工作簿时出现致命错误

时间:2017-08-29 09:39:04

标签: php excel

在运行用于连接到工作簿的代码时,我会遇到致命的错误。

以下是代码:

<?php
$filename = "C:/Users/.../Output.xlsb";
$sheet1 = "DAILY_OUTPUT";
$sheet2 = "DAILY_OUTPUT";
$excel_app = new COM("Excel.application") or Die ("Did not connect");
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook");
$Worksheet = $Workbook->Worksheets($sheet1);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
$Worksheet = $Workbook->Worksheets($sheet2);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
#To close all instances of excel:
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);

当我从PhpStorm运行到Google Chrome时,它会显示:

Fatal error: in C:\Users\...\excCon.php on line 6

编辑:“...”只是为了缩短此处的网址

1 个答案:

答案 0 :(得分:0)

解决方案是错误的斜杠。 而不是单/我放了双\,现在正确读取了文件的路径。