Solved

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

Posted on 2004-04-08
6
601 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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