【发布时间】:2014-03-21 00:52:50
【问题描述】:
我正在尝试创建一个新表格并将其插入到 MS Word 文档中,但我遇到了麻烦,任何帮助将不胜感激。我遇到以下错误:
'无法查找 `InsertTable':未知名称。 '
很明显,我访问该函数的语法不正确,但我无法找到可以简洁地告诉我如何执行此操作的资源。
代码示例:
//1. Instanciate Word
$word1 = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word1->Version}\n";
//2. specify the MS Word template document (with Bookmarks inside)
$template_file = "C:\PHP/TEST.docx";
//3. open the template document
$word1->Documents->Open($template_file);
// get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname2 = "TABLE_Budget";
if ($word1->ActiveDocument->Bookmarks->Exists($bookmarkname2)) {
//then create a Table and perform the substitution of bookmark with table
$objBookmark1 = $word1->ActiveDocument->Bookmarks($bookmarkname2);
$table1 = $word1->ActiveDocument->Tables->Add($word1->Selection->Range, 1, 2); //creates table with 2 columns
//now substitute the bookmark with actual value
$objBookmark1->InsertTable = $table1;
} else {
echo 'Problem found on ' . $bookmarkname2 . 'insert.';
}
【问题讨论】: