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
Solved

How to insert data into existing MS Excel document from php?

Posted on 2004-04-08
6
599 Views
Last Modified: 2007-12-19
I have a web app written in php/mysql running on linux server.  I also have an existing excel document (preformatted with fonts, formulas,etc).  I want to be able to insert data from the mysql database into specific cells in the Excel worksheet.

I have fairly extensive knowledge of handling the database stuff with php/mysql.  What I need is a way to get the data from php to the specific cells in Excel.  I've seen stuff on creating dynamic excel documents, but my excel sheet is already created, I just need to get data into it.  I'd also like to be able to save that excel document with a new name each time i do an export.  This way I can keep a blank template and repeat this process with new data as often as I want.

So, in short, I need to be able to open an existing excel document, drop some data in some specific cells, and then save the excel document with a new name while preserving the original excel document.

Any help is much appreciated!
0
Comment
Question by:ericwolfe
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 300 total points
ID: 10786450
Did you try

Spreadsheet_Excel_Writer: http://pear.php.net/package-info.php?pacid=156

There are several retail products available but this is one free..
0
 

Author Comment

by:ericwolfe
ID: 10787911
I hadn't seen that one yet.  Checked it out.  Looks promising....BUT...it does not appear you can edit an already existing worksheet.  At least, by what I gather from it you can't.

If I use something that generates a new page from scratch each time, I'll have to add the sheet's formatting each time I create a page.  This would be acceptable if there is an easy way to export the formatting of the page without having to hand code it.  Yeah, I am kinda lazy, but there could potentially be a lot of worksheets I would have to do this to which would be very time consuming.

If you've used the Spreadsheet_Excel_Writer and I am overlooking something about opening existing files - let me know.

Thanks.
0
 

Author Comment

by:ericwolfe
ID: 10788174
Ok, I think I'm on to something here.  I can save my current excel documents as html files.  Then, I should be able to populate the correct cells with the data using php to edit the html file.

Now, I just need an excel generator that will accept html to create the excel file.  The pear solution mentioned above does not appear to accept html to build the excel file.  
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Assisted Solution

by:jkna_gunn
jkna_gunn earned 200 total points
ID: 10789691
you should be able to put data into an existing excel sheet,
i have managed to alter data in active word and powerpoint files, the same should be true for excel.

im not at my development machine at the mo, so can't get the code.
but should be able to later today, if you still need it...
0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10791669
0
 

Author Comment

by:ericwolfe
ID: 10794781
The problem with the COM stuff is you have to running on Windows (so far as I can tell).  I'm running on linux.  And actually, today I came up with a solution.  Here's what I got working:

1. Save excel document as html.

2. Add necessary php to html to fill cells.

3. Save as php file.

4. Run another php script that opens and reads it into buffer and spits out a new file with an .xls extension.

5. Send file to user with headers

6. Delete .xls file on server.


So far, so good!  since the html generated by excel includes xml (i think thats what it is) - when you rename it back to a xls file, excel has no problems opening it.  Step 2 was a little weird...had to play around with the file in excel to see what changes it made to the html.  In my case, this didnt turn out being too bad - but I can see how this would get weird.

Anyway, thanks to both of you for contributing.
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.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 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