开发者

PHP - import data into a excel template

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 th开发者_Python百科at 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


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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜