Jump to content

How to open an Excel file through PHP


Tizza

Recommended Posts

Hi All

 

I am writing a script to automate a reporting process.  One of my steps (the last step i need to figure out) is openening an Excel document through the script.  When i manually open it and i see it on the screen, it works fine - that is... it does the data connects and runs the macro's. 

 

I am using the following code:

 

<?PHP

$excel = new COM("excel.application");
$excel->Visible = true;

//Open workbook
$wkb = $excel->Workbooks->Open('C:\Inetpub\wwwroot\test\CS.xls');

//Save the file
$wkb->SaveAs("C:\Inetpub\wwwroot\test\\$case.xls");

//Quit MS Excel
$wkb->Close(false);
$excel->Workbooks->Close();
$excel->Quit();
unset($sheet1);
unset($sheet2);
unset($excel);
?>

 

I see the process EXCEL run, then close but the file that is created does not include the data connects or macros.  Therefore it is just a blank file.

 

I have tried using an exec statement too:

exec("excel C:\Inetpub\wwwroot\\test\cs.xls");

 

but it doesnt execute.

 

Is there anything that can be done to make it so Excel will physically open on the server?  Or even better.... Excel will open and refresh its data?

 

Please let me know!!!  I have tried a lot of different methods and havnt come any closer to figuring this out :(

 

Thx!

 

~T

Link to comment
https://forums.phpfreaks.com/topic/67304-how-to-open-an-excel-file-through-php/
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.