方法一:利用php com模块。也即利用word提供的本地api,所有只适用于windows系统上。
<?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
//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);
?>
发表评论 取消回复