成都公司:成都市成华区建设南路160号1层9号
重庆公司:重庆市江北区红旗河沟华创商务大厦18楼
PHP设计模式介绍值对象模式
PHP操作word文档的二种办法
办法一:应用php com模块 。也即应用word供应的当地api,一切只合用于windows系统上。

view plaincopy to clipboardprint?
<?php
$word = new com('word.application') or die('无法翻开word');
$word->Visiable = false;
$doc_file = '/path/to/doc';
$word->Open($doc_file);
$text = '这段文字将被写到word文档中去';
$word->Selection->TypeText($text);
//保管
$word->ActiveDocument->Save();
//读取内容
$doc_file_contents = $word->ActiveDocument->Content->Text;
//输出word内容
$word->PrintOut();
$word->Close();
?>
<?php
$word = new com('word.application') or die('无法翻开word');
$word->Visiable = false;
$doc_file = '/path/to/doc';
$word->Open($doc_file);
$text = '这段文字将被写到word文档中去';
$word->Selection->TypeText($text);
//保管
$word->ActiveDocument->Save();
//读取内容
$doc_file_contents = $word->ActiveDocument->Content->Text;
//输出word内容
$word->PrintOut();
$word->Close();
?>
应用com衔接word,常常无法预期运转成功,不不变当前也不晓得是什么缘由,临时靠命运运限吧。
办法二:应用catdoc。catdoc是linux上的东西,需求自行装置装备。
view plaincopy to clipboardprint?
<?php
//catdoc地位
$cat_doc = '/usr/local/bin/catdoc';
$doc_file = 'this is a doc file';
//读取word文件内容
$doc_file_contents = shell_exec($cat_doc . ' ' . $doc_file);
echo nl2br($doc_file_contents);
?>
<?php
//catdoc地位
$cat_doc = '/usr/local/bin/catdoc';
$doc_file = 'this is a doc file';
//读取word文件内容
$doc_file_contents = shell_exec($cat_doc . ' ' . $doc_file);
echo nl2br($doc_file_contents);
?>
关于更多catdoc的相关功用,请查阅catdoc文档。
因为catdoc是linux的东西,所以上面的这段代码只能运转在linux效劳器上,罢了必需装置了catdoc。

