I have already a code for export php file to excel. My problem is I want to insert the image file into excel using php code. When I try this code below on this..
The output will look like this
"Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description :</b> Unable to get the SaveAs property of the Workbook class' in C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php:45 Stack trace: #0 C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php(45): variant->SaveAs('C:\xam pp\htdocs...') #1 {main} thrown in C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php on line 45"
Can anyone help me to debug this code. Thanks a Lot..
Code:
<?php
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$xlEdgeLeft = 7;
$xlEdgeTop = 8;
$xlEdgeBottom = 9;
$xlEdgeRight = 10;
//*** Excel Document Root ***//
$strFileName = "MyXls/Book1.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
$xlSheet1 = $xlBook->Worksheets(1);
$xlApp->Application->Visible = False;
//*** Sheet 1 ***//
$xlSheet1->Name = "My Sheet1";
//*** Write text to Row 1 Column 1 ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "ShotDev.Com";
//*** Insert Picture (1) ***//
$xlApp->Range("B3")->Select();
$xlApp->ActiveSheet->Pictures->Insert($strPath."/logo.gif")->Select();
//*** Insert Picture (2) ***//
$xlApp->Range("I3")->Select();
$Pic = $xlApp->ActiveSheet->Pictures->Insert($strPath."/logo.gif");
$Pic->Width = 300;
$Pic->Height = 150;
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
"Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description :</b> Unable to get the SaveAs property of the Workbook class' in C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php:45 Stack trace: #0 C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php(45): variant->SaveAs('C:\xam pp\htdocs...') #1 {main} thrown in C:\xampp\htdocs \sample\php_ins ert_picture\php _insert_picture .php on line 45"
Can anyone help me to debug this code. Thanks a Lot..