< 戻る 【 Calc 】
【参考サイト】
Apache OpenOffice
Programming Apache OpenOffice
The Universal Network Object(UNO) Framework
Rony G. Flatscher
Using "UNO API Info" From JavaScript
T.B.P.日本語版
12: UNOディスパッチコマンドを実行し、
全情報を取得する(Java編)
【カーソルを A1セルに移動させるサンプルコード】
//DispatchHelper
importClass(Packages.javax.swing.JOptionPane);
importClass(Packages.java.lang.System);
importClass(Packages.com.sun.star.beans.PropertyValue);
importClass(Packages.com.sun.star.frame.XDispatchHelper);
importClass(Packages.com.sun.star.frame.XDispatchProvider);
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.frame.XModel);
xSheetComponent = XSCRIPTCONTEXT.getDocument();
// utility method to ease creation of PropertyValue objects
function createProperty(n, v){
prop = new PropertyValue();
prop.Name =n;
prop.Value=v;
return prop
}
try{
// get important objects from the XSCRIPTCONTEXT
xDispatchProvider = UnoRuntime.queryInterface(XDispatchProvider, XSCRIPTCONTEXT.getDesktop());
ctx = XSCRIPTCONTEXT.getComponentContext();
// create an UNO service object
smgr = ctx.getServiceManager();
sdh = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx);
// get XDispatchProvider
oModel = UnoRuntime.queryInterface(XModel, xSheetComponent);
oController = oModel.getCurrentController();
oFrame = oController.getFrame()
oDispatchProvider = UnoRuntime.queryInterface(XDispatchProvider, oFrame);
// dispatch
args = new Array;
args[0]= createProperty('ToPoint', "A1");
xDispatchHelper = UnoRuntime.queryInterface(XDispatchHelper, sdh);
xDispatchHelper.executeDispatch(oDispatchProvider, ".uno:GoToCell", "", 0, args);
oDisp = "Success\n(LO7.6.2.1)"
}catch(e){
//Error Handling
errorname = e.name;
errormsg = e.message;
oDisp= errorname + "\n" + errormsg;
JOptionPane.showMessageDialog(null, eDisp);
}finally{
JOptionPane.showMessageDialog(null, oDisp);
prop = null;
xDispatchProvider = null;
ctx = null;
smgr = null;
sdh = null;
oModel = null;
oController = null;
oFrame = null;
oDispatchProvider = null;
args = null;
xDispatchHelper = null;
System.gc();
}