调了一天了,还是没有进展,我用java调用OpenOffice3.1 Calc,打开已有的ods文件并往里插入数据,都是正常的,但最后保存的时候总是抱错:
com.sun.star.lang.DisposedException:
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:182)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:148)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:344)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:313)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:101)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:652)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:154)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:136)
at $Proxy13.storeAsURL(Unknown Source)
不知道啥原因,我的调用保存代码如下:
public void genOdsReport(String AStartPath, String AFile) throws Exception {
Object desktop = simpleBootstrap(AStartPath);
com.sun.star.frame.XComponentLoader xCompLoader = (com.sun.star.frame.XComponentLoader) UnoRuntime
.queryInterface(com.sun.star.frame.XComponentLoader.class,
desktop);
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new com.sun.star.beans.PropertyValue();
loadProps[0].Name = "Max";
loadProps[0].Value = new Boolean(true);
Object oDocToStore = xCompLoader.loadComponentFromURL("file:///"
+ AFile, "_blank", 0, loadProps);
XComponent xSpreadsheetComponent = (XComponent) oDocToStore;
XSpreadsheetDocument ASpreadsheetDocument = getXSpreadsheetDocument(xSpreadsheetComponent);
XSpreadsheet ASpreadsheet = getXActiveSpreadsheet(xSpreadsheetComponent);
setTextValueOfXCellAtPosition(ASpreadsheet, 0, 0,
"123");
com.sun.star.frame.XStorable xStorable = (com.sun.star.frame.XStorable) UnoRuntime
.queryInterface(com.sun.star.frame.XStorable.class, oDocToStore);
com.sun.star.beans.PropertyValue[] propertyValue = new com.sun.star.beans.PropertyValue[2];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Overwrite";
propertyValue[0].Value = new Boolean(true);
propertyValue[1] = new com.sun.star.beans.PropertyValue();
propertyValue[1].Name = "FilterName";
propertyValue[1].Value = "StarOffice XML (Clac)";// "StarOffice XML (Writer)";
String sSaveUrl = "file:///" + AFile;// "c:/YNGS/1.ods";
System.err.println("oDocToStore = " + sSaveUrl);
try {
xStorable.storeAsURL(sSaveUrl.toString(), propertyValue);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
};
就是最后一句:xStorable.storeAsURL(sSaveUrl.toString(), propertyValue);报错...



