-
Dec 11, 2008, 08:30 AM
#1
Creating an word doc from PHP/Mysql
Hi all
Do anyone know how to creat an word document using PHP. I have a form pulls data from a mysql database and display in the form. What i want to do is to have a button which will when click send the details of the user address and name from the form to a .doc word document.
Anyone have any ideas of how this can me done?
-
Dec 11, 2008, 09:24 AM
#2
Creating a word document using PHP
<?php
$word = new COM("word.application") or die ("couldnt create an instance of word");
echo "loaded , word version{$word->version}";
//bring word to the front
$word->visible = 1;
//open a word document
$word->Documents->Add();
//add some text to the document
$word->Selection->TypeText("this is some sample text in the document");
//save the document as sampleword.doc
$word->Documents[1]->SaveAs("sampleword.doc");
//close word
$word->Quit();
//free object resources
$word->Release();
$word = null;
?>
-
Dec 11, 2008, 09:40 AM
#3
simpler to create a RTF file but either way you have to look up changing "content headers" in you php file
-
Dec 11, 2008, 09:46 AM
#4
thanks guys, would this script also carry the values from the form to the word doc? e.g. name, address fields?
-
Dec 11, 2008, 11:26 AM
#5
Creating a word document using PHP
your objective can also be completed using this simple snippet.
$fp = fopen("document.doc", 'w+');
$str = "<B>This is the text for the word file created through php programming</B>";
fwrite($fp, $str);
fclose($fp);
-
Dec 11, 2008, 12:39 PM
#6
Did you accomplished the task successfully?
-
Jan 26, 2009, 04:52 PM
#7
yes got this done, thanks all for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules