Page 1 of 1
Generate MSword DOC
Posted: Thu Nov 18, 2004 3:02 am
by popper
Hello everybody
how can i generate ms doc files using php? (version doesnt matter)
i 've tried the following code:
Code: Select all
header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="my.doc";');
echo "Helloooooooooooooooooo";
But it doesn't work. Do i have to change something particular in apache/php.ini config files?
i search the site but i find only parser to generate html from doc file, i need the opposite procedure.
thanks all,
bye
Davide
Posted: Thu Nov 18, 2004 3:09 am
by phpScott
search the forum for ms word.
I've done it for you
viewtopic.php?t=27003
It has a link to where you can read about php and creating word documents.
phpScott
Posted: Thu Nov 18, 2004 4:21 am
by popper
10x man, i've searched only in the site

.
now it work, i've used this code
Code: Select all
?php
// Word execution
$word = new COM("word.application") or die("Non sono riuscito ad eseguire Word");
$word->Visible = 1;
//open empty doc
$word->Documents->Add();
//text operations
$word->Selection->TypeText("formattazione lettera blalblallb\n\n nome cliente " . $_POSTїtesto]);
$word->Documentsї1]->SaveAs("e:\webroot\ciao.doc");
//close Word
$word->Quit();
//send to browser
$word->Release();
$word = null;
header("Content-type: application/msword");
header('Content-Disposition: attachment; filename="ciao.doc"');
readfile("ciao.doc");
?>
this script create a doc file, using the text passed by a post form.
Then it send the file to the browser for downloading/opening.
Posted: Thu Nov 18, 2004 5:02 am
by timvw
What happens if this script is executed by more than one person at the same time?
a possible scenario
person1: write document e:\foo.doc
person2:write document e:\foo.doc
person1: recieve e:\foo.doc
<-- concurrency problem! save the documents using a unique filename
Posted: Thu Nov 18, 2004 8:35 am
by popper
this is a test code, only to try if ms doc generation works. In "final version" ill'put some synchronization, doc's file name probably will be determinated by unique mysql's table key.