[已解决]Java调用OpenOffice Calc,打开ods文件,无法保存(急...)

创建宏-编写脚本-使用API

版主: fong

[已解决]Java调用OpenOffice Calc,打开ods文件,无法保存(急...)

帖子holyrain » 2009-11-06 15:23

调了一天了,还是没有进展,我用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);报错...
最后由 holyrain 编辑于 2009-11-09 08:25,总共编辑了 1 次
OpenOffice 3.1 on Windows Vista
holyrain
无名小卒
无名小卒
 
帖子: 2
注册: 2009-11-04 16:43
Oo版本: 3.1.X
主要OS: MS Windows Vista
其它OS: Linux

Re: Java调用OpenOffice Calc,打开ods文件,无法保存(急...)

帖子hyl0214 » 2009-11-06 17:46

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)";

除了第一行都给去掉试试
OpenOffice 3.1 on Windows XP
hyl0214
初来乍到
初来乍到
 
帖子: 13
注册: 2009-09-03 15:32
Oo版本: 3.1.X
主要OS: Ms Windows XP
其它OS: OpenOffice 3.1 on Windows Vist

Re: Java调用OpenOffice Calc,打开ods文件,无法保存(急...)

帖子holyrain » 2009-11-09 08:24

还真是这样,谢谢啦...唉...参考sdk的sample怎么反而是错的呢,郁闷ing...
OpenOffice 3.1 on Windows Vista
holyrain
无名小卒
无名小卒
 
帖子: 2
注册: 2009-11-04 16:43
Oo版本: 3.1.X
主要OS: MS Windows Vista
其它OS: Linux


回到 宏与UNO API

在线用户

正在浏览此版面的用户:Google [Bot] 和 1 位游客