PHP tutorials Generate word two ways
1. Create Word with normal touch
2.fopen Open Word
3.fwrite write to Word and save
This will cause a problem if you write something that contains HTML code, it will be written directly to Word instead of typeset.
This problem requires a piece of code in the header of the output HTML code
$headert = ' xmlns:w= ' Urn:schemas-microsoft-com:office:word "
xmlns= "HTTP://WWW.W3.ORG/TR/REC-HTML40" > ";
$footer = "";
For example, your content is $text;
Then $text= $header when writing. $text. $footer;
In this way, the contents of FCK can be output according to the layout style!
Method One
$word = new COM ("Word.Application") or Die ("unable to
Create Word document ");
Print "Loaded word, version{$word->version}n";
$word->visible = 0;
$word->documents->add ();
Set margin this has an error
$word->selection->agesetup->rightmargin = ' 3 ";
Set the font for this
$word->selection->font->name = ' Helvetica ';
Set Font size
$word->selection->font->size = 8;
Set color
$word->selection->font->colorindex= 13; wddarkred= 13
Output to document
$word->selection->typetext ("Hello World");
$range = $word->activedocument->range (0,0);
$table _t = $word->activedocument->tables->add ($range, 3,4);
$table _t->cell (->range->insertafter) (' AAA ');
Save
$word->sections->add (1);
$word->documents[1]->saveas (DirName (__file__). " /create_test.doc ");
Exit
$word->quit ();
?>
Method Two
Class Word
{
function Start ()
{
Ob_start ();
print ' xmlns:w= ' Urn:schemas-microsoft-com:office:word "
xmlns= "HTTP://WWW.W3.ORG/TR/REC-HTML40" > ";
}
function Save ($path)
{
Print "";
$data = Ob_get_contents ();
Ob_end_clean ();
$this->wirtefile ($path, $data);
}
function Wirtefile ($FN, $data)
{
$FP =fopen ($FN, "WB");
Fwrite ($fp, $data);
Fclose ($FP);
}
}
?>
Calling methods
$word =new Word;
$word->start ();
Echo $cout;
$wordname = "word/". Time (). ". Doc ";
$word->save ($wordname);//save Word and end
http://www.bkjia.com/PHPjc/444807.html www.bkjia.com true http://www.bkjia.com/PHPjc/444807.html techarticle PHP Tutorial generates word two ways 1. Normal touch Create word 2.fopen open Word 3.fwrite write word and save this will cause a problem if you write something inside that contains HTML code ...