tags:

views:

399

answers:

4

Hello, first off I am fairly new to php like 3 weeks working with it, and am loving it so far. Its a fantastic language. I am running into a issue though, I have a client who wants the information collected in on a form on this website to then be imported into a excel documents that he already has created. Since I am fairly new I've been googleing for the past two hours and have come up with so many different answers that my head is spinning.

I was wondering if someone can instruct me if first this can be done and what is the best method.

Or if you know a website that might have already explained this in a simple way if you could direct me to that.

Thanks guys, hopefully someday I can be as smart as you :)

Peace

A: 

To start with, you're going to need a library capable of reading your Excel template, such as PHPExcel, which you can then populate with the data from the form and save

Mark Baker
+1  A: 

Hey Chris, Sounds like what you are needing to do is call a COM object (Excel automation), from PHP. I Googled calling COM objects from PHP and found a site that suggested doing something like this.. the sample is for word but it should be simple to translate the idea to excel.. As discussed below, can you assume windows? Is this code running against excel on the browser machine or against some excel data on the server?

<? 
$word=new COM("word.application") or die("Cannot start word for you"); 
print "Loaded word version ($word->Version)\n"; 
$word->visible =1; 
$word->Documents->Add(); 
$word->Selection->Typetext("Dit is een test"); 

New efficiencies lie ahead
See the new IBM System x3650 M3 Express$word->Documents[1]->SaveAs("burb ofzo.doc"); 
$word->Quit(); 
?> 

Here is a link to using COM from PHP:

PHP: COM

Steve Sheldon
COM is an option only if the client website is running on a Windows server with MS Excel installed
Mark Baker
You're right, I assumed that since they are working with Excel they were on Windows. Not sure if this is a safe assumption here. It wasn't specified. Also doesn't say whether this is code that will run on client or the server.
Steve Sheldon
I will have to verify this, he just gave me the excel file that he wants me to work with, and asked that I populate that excel file with the data from the form. I do not know anything about the server, I will check with him. Thank you everyone for your responses so far.
Chris
Client's desktops will almost certainly have MS Excel, but no guarantees for their web servers
Mark Baker
A: 

Our answer is to save them as is into the database and convert them to <BR> for display to a web page. That way if a non-web program looks at the data, it will display semi-correctly without change. Yes some things won't always display properly for the program, but they will for the web page.

Dave
Have you answered the wrong question here? It doesn't seem related to this question in any way at all!
Mark Baker
A: 

Saving the data in a .csv (comma delimited) file may be a quick option if you can arrange the spreadsheet at all.

Orbit
Unlikely to be an option as the client has apparently already created a template xls file for import of the data, so they'll expect the genuine article
Mark Baker