创建文档;
<?php $html = "this is question"; for($i=1;$i<=3;$i++){ $word = new word(); $word->start(); $wordname = ‘xxxx‘.$i.".doc"; echo $html; $word->save($wordname); ob_flush(); flush(); } class word { function start() { ob_start(); echo ‘<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">‘; } function save($path) { echo "</html>"; $data = ob_get_contents(); ob_end_clean(); $this->wirtefile ($path,$data); } function wirtefile ($fn,$data) { $fp=fopen($fn,"wb"); fwrite($fp,$data); fclose($fp); } } ?>
读取文档
<?php $word = new COM("word.application") or die ("Could not initialise MS Word object."); $word->Documents->Open(realpath("Sample.doc")); // Extract content. $content = (string) $word->ActiveDocument->Content; echo $content; $word->ActiveDocument->Close(false); $word->Quit(); $word = null; unset($word); ?>
时间: 2024-10-27 07:46:17