以下这段代码,可以打开word文档并编辑指定字符串,但请问有人知道怎么在保留原有word的样式的情况下替换吗?
note:$test= $word->ActiveDocument->content->Text; 这句语句获取了word的文档内容,但是并没有获取word的格式。例如,加粗、斜体、下划线等样式都没有了。
<?
$word = new COM(”word.application”) or die(”Can't start Word!”);
$word->Documents->OPen(”d:\web\muban.doc”);
$test= $word->ActiveDocument->content->Text;
echo $test;
echo “<br>”;
$test=str_replace(”<{变量}>”,”这是变量”,$test);
echo $test;
$word->Documents->Add();
$word->Selection->TypeText(”$test”);
$word->Documents[1]->SaveAs(”d:/myweb/comtest.doc”);
$word->Quit();
?>