我已经能够创建表格并将其添加到我的单词模板中,并且我一直在搜索MSDN以寻找一种通过COM控制此新表属性的方法,但我只是没有找到任何东西,MSDN/Google/stackoverflow,如果有人有控制以这种方式创建的表的经验,将不胜感激!
示例问题,下面在我的Word文档中的特定点创建了一个简单的两列1行表,但它基本上没有设置任何属性,我需要添加边框等,ATM基本上是不可见的,除非您突出显示单词中的单元格。
$table1 = $word1->ActiveDocument->Tables->Add($objBookmark1->Range, 1, 2)
我知道我需要进一步扩展此语句,也许可以使用对样式或其他内容的引用,但我找不到有效的命令,请继续得到以下内容:
未捕获的异常"com_exception",消息为"无法查找" "线条样式":未知名称。
好的,我已经找到了一个解决方案,我希望这将对将来的某人有所帮助:
final class WdLineStyle {
const wdLineStyleSingle = 1;
// ...
}
//Bookmark found in word document - you want to find this and replace it with the table
$bookmarkname2 = "TABLE_Budget";
// Wrapped in an 'if' find the correct bookmark and then create a Range and perform the table insertion. STYLING!!!!!
if ($word1->ActiveDocument->Bookmarks->Exists($bookmarkname2)) {
//then create a Table and perform the substitution of bookmark with table
$ActiveD = $word1->ActiveDocument;
$objBookmark1 = $ActiveD->Bookmarks($bookmarkname2);
$Table1 = $ActiveD->Tables->Add($objBookmark1->Range, 3, 4);
$Table1->Borders->InsideLineStyle = WdLineStyle::wdLineStyleSingle;
$Table1->Borders->OutsideLineStyle = WdLineStyle::wdLineStyleSingle;
echo 'Succeafully inserted ' . $bookmarkname2 . "<br />";
} else {
echo 'Problem found on ' . $bookmarkname2 . 'insert.';
}