Home > php教程 > php手册 > PHP在保留样式的前提下编辑WORD模板

PHP在保留样式的前提下编辑WORD模板

WBOY
Release: 2016-06-06 19:40:45
Original
1317 people have browsed it

以下这段代码,可以打开word文档并 编辑 指定字符串,但请问有人知道怎么在 保留 原有word的 样式 的情况下替换吗? note: $test= $word-ActiveDocument-content-Text; 这句语句获取了word的文档内容,但是并没有获取word的格式。例如,加粗、斜体、下划线

以下这段代码,可以打开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 “
”; 
$test=str_replace(””,”这是变量”,$test); 
echo $test; 
$word->Documents->Add(); 
$word->Selection->TypeText(”$test”); 
$word->Documents[1]->SaveAs(”d:/myweb/comtest.doc”); 
$word->Quit(); 
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template