473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

I have already code for exporting excel file from php, and it works properly. But i h

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..

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     //*** Get Document Path ***//
  4.     $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
  5.  
  6.     $xlEdgeLeft = 7;
  7.     $xlEdgeTop = 8;
  8.     $xlEdgeBottom = 9;
  9.     $xlEdgeRight = 10;
  10.  
  11.     //*** Excel Document Root ***//
  12.     $strFileName = "MyXls/Book1.xls";
  13.  
  14.     //*** Connect to Excel.Application ***//
  15.     $xlApp = new COM("Excel.Application");
  16.     $xlBook = $xlApp->Workbooks->Add();
  17.     $xlSheet1 = $xlBook->Worksheets(1);
  18.     $xlApp->Application->Visible = False;    
  19.  
  20.  
  21.     //*** Sheet 1 ***//
  22.     $xlSheet1->Name = "My Sheet1";
  23.  
  24.     //*** Write text to Row 1 Column 1 ***//        
  25.     $xlApp->ActiveSheet->Cells(1,1)->Value = "ShotDev.Com";
  26.  
  27.     //*** Insert Picture (1) ***//
  28.     $xlApp->Range("B3")->Select();
  29.     $xlApp->ActiveSheet->Pictures->Insert($strPath."/logo.gif")->Select();
  30.  
  31.  
  32.     //*** Insert Picture (2) ***//
  33.     $xlApp->Range("I3")->Select();
  34.     $Pic = $xlApp->ActiveSheet->Pictures->Insert($strPath."/logo.gif");
  35.     $Pic->Width = 300;
  36.     $Pic->Height = 150;
  37.  
  38.     @unlink($strFileName); //*** Delete old files ***//    
  39.  
  40.     $xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
  41.  
  42.     //*** Close & Quit ***//
  43.     $xlApp->Application->Quit();
  44.     $xlApp = null;
  45.     $xlBook = null;
  46.     $xlSheet1 = null;
  47. ?>
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_insert_picture\php_inse rt_picture.php:45 Stack trace: #0 C:\xampp\htdocs\sample\php_insert_picture\php_inse rt_picture.php(45): variant->SaveAs('C:\xampp\htdocs...') #1 {main} thrown in C:\xampp\htdocs\sample\php_insert_picture\php_inse rt_picture.php on line 45"

Can anyone help me to debug this code. Thanks a Lot..
Attached Images
File Type: jpg AMTI.jpg (7.7 KB, 99 views)
File Type: jpg export.jpg (96.4 KB, 108 views)
Jan 27 '14 #1
0 1216

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
3
by: Andres Romero | last post by:
I have a button in my html page for exporting to excel files using the RenderControl function. When the table generated is small in rows size it works fine, but when there are much more rows (more...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
7
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user...
1
by: Darrenovic | last post by:
Hi, I'm using Vista and i have some issue that i need to know in order to do it efficiently in Ms SQL server 2008. I have an excel/word file with all the tables name in a column along their...
1
by: JFKJr | last post by:
Hi! I have exported an access table data into an excel file using the following code. However, the code exported all the data to the excel sheet starting from 'A' cell (first column). But I want to...
2
by: phanimadhav | last post by:
Hello Experts, I developed following code for excel file creation by using Dataset.But i got the following error(NullRefernec Exception was caught) at the response.End() My...
5
by: ncsthbell | last post by:
I am using a query to select my columns from a table and then I am using the export function to export the results to an excel spreadsheet. I need to add to blank columns to the end, "Verified Year"...
3
by: harry2012 | last post by:
Hello, I do have an access form called T4, which is exported to an excel file, where i do have complex formulas and calculations. I would some assistance in exporting the table to excel. I...
1
by: Hema Suresh | last post by:
Hi all I am going mad of this problem Please someone help me I used vb and excel to save a database I used oXLBook.Save "To save the file" oXLBook.Close "To close it properly ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.