public boolean insert(int steps, String str) throws Exception
{
int start = Dispatch.get(this.cursor, "Start").getInt() + steps;
Dispatch.put(this.cursor, "Start", start);
Dispatch.call(this.cursor, "InsertBefore", str);
//this.getCount();
Dispatch.put(this.cursor, "Start", start + str.length());
//System.out.println(Dispatch.get(this.cursor, "Start").getInt() + " " + (Dispatch.get(this.cursor, "Start").getInt()+Dispatch.get(this.cursor, "End").getInt()));
return true;
}
public boolean replace(String str) throws Exception
{
Dispatch.put(this.cursor, "Text", str);
return true;
}
public int getTableNum() throws Exception
{
return Dispatch.get(this.tables, "Count").getInt();
}
public boolean setCurrentTable(int index) throws Exception
{
this.table = Dispatch.call(this.tables, "Item", new Variant(index)).toDispatch();
Dispatch.call(this.table, "Select");
return true;
}
public String getCell(int row, int col) throws Exception
{
Dispatch cell = Dispatch.call(table, "Cell", Integer.toString(row), Integer.toString(col)).toDispatch();
Dispatch.call(cell,"Select");
String tmp = Dispatch.get(this.cursor, "Text").getString();
//System.out.println(".." + tmp);
if (tmp.length() > 2)
{
return tmp.substring(0, tmp.length() - 2);
}
else
return "";
}
public boolean replaceCell(int row, int col, String str) throws Exception
{
Dispatch cell = Dispatch.call(table,"Cell", Integer.toString(row), Integer.toString(col)).toDispatch();
Dispatch.call(cell, "Select");
Dispatch.put(this.cursor, "Text", str);
return true;
}
public static void main(String args[])
{
WordHandle word = new WordHandle();
try
{
word.open("D://doc//tax//开业登记合并事项实地调查表.doc", false);
System.out.println(word.getTableNum());
word.setCurrentTable(1);
word.replaceCell(1, 2, "old Name");
word.replaceCell(3, 1, "经营范围");
word.replaceCell(4, 2, "5654654747");
word.replaceCell(4, 4, "1111111111");
word.replaceCell(5, 2, "1111111111");
word.saveAs("D://开业登记合并事项实地调查表.doc");
word.close();
word.quit();
}
catch (Exception e)
{
}
}
}
当然要运行上面的代码需要下载jacob,下载地址为http://sourceforge.net/project/jacob-project
还需要将jacob.dll放入C:\WINDOWS\system32下,jacob.jar放在classpath下。