[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP script to run excel macro - parse error

Posted on 2010-11-21
3
Medium Priority
?
2,303 Views
Last Modified: 2012-05-10
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
Comment
Question by:rlb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:rlb1
ID: 34184997
Parse error: syntax error, unexpected T_STRING in /mnt/target02/347537/www.********.net/web/content/phpexcelscript.php on line 3
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 1000 total points
ID: 34185569
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
 
LVL 3

Assisted Solution

by:Prograministrator
Prograministrator earned 1000 total points
ID: 34185699
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question