Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-08
6
Medium Priority
?
606 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 900 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Assisted Solution

by:jkna_gunn
jkna_gunn earned 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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