网上关于jacob如何操控word的例子已经有很多,但基本处理出来的表格,是没有边框线的。
在这里对此我做点补充,jacob版本是1.17
ActiveXComponent word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(true));
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));
}
....略