/** *//**
* 创建表格
*
* @param pos 位置
* @param cols 列数
* @param rows 行数
*/
public void createTable(String pos, int numCols, int numRows) {
if (!find(pos)) {
Dispatch tables = Dispatch.get(document, "Tables").toDispatch();
Dispatch range = Dispatch.get(selection, "Range").toDispatch();Dispatch table = Dispatch.call(tables, "Add", range, new Variant(5),new Variant(5)).toDispatch();
Dispatch newTable = Dispatch.call(tables, "Add", range,
new Variant(numRows), new Variant(numCols)).toDispatch();
Dispatch.call(selection, "MoveRight");
}
}
上面是代码 生成的表格时没有边框线的 请问怎么设置边框线
Jacob没用过,但是看了下,它使用的是vba com接口,所以你在得到table对象以后找找 Borders 属性
比如在VBA里用下面的代码
Borders(wdBorderTop).LineStyle = wdLineStyleSingle //这个代码设置上边线为单线条风格
在jacob里看看有没有对应的。
Dispatch documents = word.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.call(documents, "Open", "e:/abc.doc").toDispatch();
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要设置的表格,这里是第一个表格
//width 是宽度值,但top时会出错,不明
Dispatch table = Dispatch.call(tables, "Item", new Variant(1)).toDispatch();
for(int b=1;b<=6;b++){
Dispatch oBorders = Dispatch.call(table, "Borders", 0-b).toDispatch();
Dispatch.put(oBorders, "LineStyle", new Variant(1));
//top第一行时,linewidth设置有错,不明原因
//Dispatch.put(oBorders, "LineWidth", new Variant(width));
}