[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2375
  • Last Modified:

PHP script to run excel macro - parse error

How do I fix this parse error?  

I am getting a parse error on Line 3 and I cannot figure out what the problem is.  Please assist.

Thanks!
<?php 
// set up excel 
$excel = new COM(”excel.application”) or die(”Unable to instantiate excel”); 
// run Excel silently, since we don’t want dialog boxes popping up in the background 
$excel->DisplayAlerts = false; 
// open up Excel file and select the first sheet, which contains the inputs 
$excel->Workbooks->Open(”/Documents/model.xls”); 
$book = $excel->ActiveWorkbook; 
$sheets = $book->Sheets; 
$sheet = $book->Worksheets(1); 
  
// input stuff into excel spreadsheet 
for ($i = 0; $i < count($_POST[input]); $i++) { 
$cell = $sheet->Cells(1, $i + 1); 
$cell->Activate; 
$cell->value = $input[$i]; 
} 
  
// run macro 
$excel->Run(”runModel”); 
  
// save spreadsheet 
$book->SaveAs(”/Documents/model.xls”); 
  
// quit Excel and clean up 
$book->Close(false); 
unset($sheets); 
$excel->Workbooks->Close(); 
unset($book); 
$excel->Quit; 
unset($excel); 
<?php 
// set up excel 
$excel = new COM(”excel.application”) or die(”Unable to instantiate excel”); 
// run Excel silently, since we don’t want dialog boxes popping up in the background 
$excel->DisplayAlerts = false; 
// open up Excel file and select the first sheet, which contains the inputs 
$excel->Workbooks->Open(”/Documents/model.xls”); 
$book = $excel->ActiveWorkbook; 
$sheets = $book->Sheets; 
$sheet = $book->Worksheets(1); 
  
// input stuff into excel spreadsheet 
for ($i = 0; $i < count($_POST[input]); $i++) { 
$cell = $sheet->Cells(1, $i + 1); 
$cell->Activate; 
$cell->value = $input[$i]; 
} 
  
// run macro 
$excel->Run(”runModel”); 
  
// save spreadsheet 
$book->SaveAs(”/Documents/model.xls”); 
  
// quit Excel and clean up 
$book->Close(false); 
unset($sheets); 
$excel->Workbooks->Close(); 
unset($book); 
$excel->Quit; 
unset($excel); 

?>

Open in new window

0
rlb1
Asked:
rlb1
2 Solutions
 
rlb1Author Commented:
Parse error: syntax error, unexpected T_STRING in /mnt/target02/347537/www.********.net/web/content/phpexcelscript.php on line 3
0
 
Shinesh PremrajanCommented:
Repalce all the occurebnce of the

$excel = new COM(”excel.application”) or die(”Unable to instantiate excel”);

”   With this   " .

You are using a double quotes used in MS office application.

$excel = new COM("excel.application") or die("Unable to instantiate excel");

Hope this helps

0
 
PrograministratorCommented:
Hello,

You wrote your code with non-standard encoding for php, this (”) double quotes can't parsed normally with php.
To fix this problem, in your editor or IDE save your file with utf8 encoding.

Note :
I'm not talking about page's display encoding, but I'm talking about source code encoding.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now