php创建读取 word.doc文档

 创建文档;

<?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); 
?>

  

原文地址:https://www.cnblogs.com/sunxun/p/4470670.html