{"id":859,"date":"2004-11-09T17:30:00","date_gmt":"2004-11-09T08:30:00","guid":{"rendered":"\/?p=859"},"modified":"2008-12-23T11:57:28","modified_gmt":"2008-12-23T02:57:28","slug":"openoffice-uno","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/859.html","title":{"rendered":"OpenOffice UNO"},"content":{"rendered":"<p>OpenOffice\u306fUNO(Universal Network Objects)\u3092\u4f7f\u7528\u3057\u3066API\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3002\n<\/p>\n<p>\n<a href=\"http:\/\/development.openoffice.org\/index.html\">OpenOffice.org for Developers<\/a>\u306e[SDK]-[SDK Download (1.0.2 SDK should be used for OOo 1.0.3.x)]\u304b\u3089OpenOffice SDK \u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3068\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u5145\u5b9f\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u3042\u308b\u7a0b\u5ea6\u306f\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3060\u308d\u3046\u304b\u3002\n<\/p>\n<p>\u307e\u305a\u306f\u3001[SDK]-[Developer&#8217;s Guide (part of SDK)]\u304b\u3089\u305f\u3069\u308c\u308b\u3001<a href=\"http:\/\/api.openoffice.org\/docs\/DevelopersGuide\/FirstSteps\/FirstSteps.htm\">2    First Steps<\/a> \u3092\u8aad\u3093\u3067\u307f\u308b\u3068\u8a00\u3046\u306e\u3082\u3088\u3055\u305d\u3046\u3002\n<\/p>\n<p>Linux\u3067OpenOffice\u3067UNO\u3092\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u30b3\u30de\u30f3\u30c9\u3092\u3046\u3064\u3002\u305f\u3060\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u7528\u753b\u9762\u3092\u8868\u793a\u3057\u3066\u52d5\u304b\u3057\u305f\u3044\u5834\u5408\u306f -headless \u306f\u3044\u3089\u306a\u3044\u3002<\/p>\n<div class=\"code\">soffice -headless \\<br \/>\n&#8220;-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager&#8221; &#038;<\/div>\n<p>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u5909\u3048\u308b\u65b9\u6cd5\u306f1.0.2\u30681.1.x\u3067\u306f\u8a2d\u5b9a\u65b9\u6cd5\u304c\u9055\u3046\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3002\u3053\u3053\u3067\u306f1.1.x\u3067\u306e\u5bfe\u5fdc\u65b9\u6cd5\u3092\u66f8\u3044\u3066\u304a\u304f\u3002\n<\/p>\n<p>$OfficePath\/share\/registry\/data\/org\/openoffice\/Setup.xcu \u3092\u30a8\u30c7\u30a3\u30bf\u3067\u958b\u3044\u3066\u7de8\u96c6\u3059\u308b\u3002&lt;node oor:name=&#8221;Office&#8221;\/&gt;\u3068\u3044\u3046\u30a8\u30ec\u30e1\u30f3\u30c8\u306e\u30dc\u30c7\u30a3\u90e8\u306b\u3001\u6b21\u306eprop\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<p><div class=\"code\">&lt;prop oor:name=&#8221;ooSetupConnectionURL&#8221; oor:type=&#8221;xs:string&#8221;&gt;<br \/>\n &lt;value&gt;socket,host=localhost,port=8100;urp;&lt;\/value&gt;<br \/>\n&lt;\/prop&gt;<\/div>\n<\/p>\n<p>\u3053\u306e\u8a2d\u5b9a\u306b\u3088\u308a\u3001OpenOffice.org\u3092\u8d77\u52d5\u3059\u308b\u3068\u30018100\u30dd\u30fc\u30c8\u3067\u30bd\u30b1\u30c3\u30c8\u7d4c\u7531\u306eUNO\u30ea\u30e2\u30fc\u30c8\u30d7\u30ed\u30c8\u30b3\u30eb(urp)\u901a\u4fe1\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3002\n<\/p>\n<p>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u3057\u3066\u3042\u308a\u3001\u500b\u4eba\u5358\u4f4d\u3067\u3053\u306e\u8a2d\u5b9a\u3092\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001$OfficePath\/user\/registry\/data\/org\/openoffice\/Setup.xcu\u306b\u3053\u3053\u3067\u793a\u3057\u305fprop\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002\n<\/p>\n<p>\u3042\u3068\u306fsoffice\u3092\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3059\u308c\u3070\u3088\u3044\u3002\u52d5\u4f5c\u78ba\u8a8d\u306fnetstat\u30b3\u30de\u30f3\u30c9\u306a\u3069\u30678100\u30dd\u30fc\u30c8\u304c\u958b\u3044\u3066\u3044\u308b\u304b\u307f\u308c\u3070\u3044\u3044\u3002<\/p>\n<div class=\"code\">$ soffice &#038;<br \/>\n$ netstat -a | grep 8100<br \/>\ntcp        0      0 localhost.localdom:8100 *:*                     LISTEN<\/div>\n<p><!--more--><\/p>\n<p>OpenOffice.org SDK \u306e\u30b5\u30f3\u30d7\u30eb\u3092\u3061\u3087\u3063\u3068\u3060\u3051\u3055\u308f\u3063\u3066\u3001Impress\u306e\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u9589\u3058\u308b\u51e6\u7406\u3092useConnection3\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u8ffd\u52a0\u3057\u3066\u307f\u305f\u3002<\/p>\n<div class=\"code\" style=\"overflow: scroll; width: 490px; white-space: nowrap;background-color:black;color:white;\">\nimport&nbsp;com.sun.star.beans.PropertyValue&#x3b;<br \/>\nimport&nbsp;com.sun.star.lang.XComponent&#x3b;<br \/>\nimport&nbsp;com.sun.star.sheet.XSpreadsheetDocument&#x3b;<br \/>\nimport&nbsp;com.sun.star.sheet.XSpreadsheets&#x3b;<br \/>\nimport&nbsp;com.sun.star.sheet.XSpreadsheet&#x3b;<br \/>\nimport&nbsp;com.sun.star.sheet.XSpreadsheetView&#x3b;<br \/>\nimport&nbsp;com.sun.star.table.XCell&#x3b;<br \/>\nimport&nbsp;com.sun.star.frame.XModel&#x3b;<br \/>\nimport&nbsp;com.sun.star.frame.XController&#x3b;<br \/>\nimport&nbsp;com.sun.star.frame.XComponentLoader&#x3b;<br \/>\nimport&nbsp;com.sun.star.bridge.XUnoUrlResolver&#x3b;<br \/>\nimport&nbsp;com.sun.star.uno.UnoRuntime&#x3b;<br \/>\nimport&nbsp;com.sun.star.uno.XComponentContext&#x3b;<br \/>\nimport&nbsp;com.sun.star.lang.XMultiComponentFactory&#x3b;<br \/>\nimport&nbsp;com.sun.star.beans.XPropertySet&#x3b;<\/p>\n<p>public&nbsp;class&nbsp;FirstConnection&nbsp;extends&nbsp;java.lang.Object&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;XComponentContext&nbsp;xRemoteContext&nbsp;=&nbsp;null&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;XMultiComponentFactory&nbsp;xRemoteServiceManager&nbsp;=&nbsp;null&#x3b;<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FirstConnection&nbsp;firstConnection1&nbsp;=&nbsp;new&nbsp;FirstConnection()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstConnection1.useConnection()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstConnection1.useConnection3()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(java.lang.Exception&nbsp;e)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;finally&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(0)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;void&nbsp;useConnection3()&nbsp;throws&nbsp;java.lang.Exception&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteServiceManager&nbsp;=&nbsp;this.getRemoteServiceManager(&quot;uno&#x3a;socket,host=localhost,port=8100&#x3b;urp&#x3b;StarOffice.ServiceManager&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;get&nbsp;the&nbsp;Desktop,&nbsp;we&nbsp;need&nbsp;its&nbsp;XComponentLoader&nbsp;interface&nbsp;to&nbsp;load&nbsp;a&nbsp;new&nbsp;document<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;desktop&nbsp;=&nbsp;xRemoteServiceManager.createInstanceWithContext(&quot;com.sun.star.frame.Desktop&quot;,&nbsp;xRemoteContext)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;query&nbsp;the&nbsp;XComponentLoader&nbsp;interface&nbsp;from&nbsp;the&nbsp;desktop<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XComponentLoader&nbsp;xComponentLoader&nbsp;=&nbsp;(XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class,&nbsp;desktop)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;create&nbsp;empty&nbsp;array&nbsp;of&nbsp;PropertyValue&nbsp;structs,&nbsp;needed&nbsp;for&nbsp;loadComponentFromURL<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;Preparing&nbsp;properties&nbsp;for&nbsp;loading&nbsp;the&nbsp;document<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;PropertyValue[]&nbsp;loadProps&nbsp;=&nbsp;new&nbsp;PropertyValue[1]&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PropertyValue[]&nbsp;loadProps&nbsp;=&nbsp;new&nbsp;PropertyValue[0]&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;Setting&nbsp;the&nbsp;flag&nbsp;for&nbsp;hidding&nbsp;the&nbsp;open&nbsp;document<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;loadProps[&nbsp;0&nbsp;]&nbsp;=&nbsp;new&nbsp;PropertyValue()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;loadProps[&nbsp;0&nbsp;].Name&nbsp;=&nbsp;&quot;Hidden&quot;&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;loadProps[&nbsp;0&nbsp;].Value&nbsp;=&nbsp;new&nbsp;Boolean(true)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;load&nbsp;new&nbsp;impress&nbsp;file<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XComponent&nbsp;xImpressComponent&nbsp;=&nbsp;xComponentLoader.loadComponentFromURL(&quot;private&#x3a;factory&#x2f;simpress&quot;,&nbsp;&quot;_blank&quot;,&nbsp;0,&nbsp;loadProps)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xImpressComponent.dispose()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;catch(&nbsp;com.sun.star.lang.DisposedException&nbsp;e&nbsp;)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteContext&nbsp;=&nbsp;null&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;e&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;void&nbsp;useConnection2()&nbsp;throws&nbsp;java.lang.Exception&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteServiceManager&nbsp;=&nbsp;this.getRemoteServiceManager(&quot;uno&#x3a;socket,host=localhost,port=8100&#x3b;urp&#x3b;StarOffice.ServiceManager&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;get&nbsp;the&nbsp;Desktop,&nbsp;we&nbsp;need&nbsp;its&nbsp;XComponentLoader&nbsp;interface&nbsp;to&nbsp;load&nbsp;a&nbsp;new&nbsp;document<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;desktop&nbsp;=&nbsp;xRemoteServiceManager.createInstanceWithContext(&quot;com.sun.star.frame.Desktop&quot;,&nbsp;xRemoteContext)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;query&nbsp;the&nbsp;XComponentLoader&nbsp;interface&nbsp;from&nbsp;the&nbsp;desktop<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XComponentLoader&nbsp;xComponentLoader&nbsp;=&nbsp;(XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class,&nbsp;desktop)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;create&nbsp;empty&nbsp;array&nbsp;of&nbsp;PropertyValue&nbsp;structs,&nbsp;needed&nbsp;for&nbsp;loadComponentFromURL<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PropertyValue[]&nbsp;loadProps&nbsp;=&nbsp;new&nbsp;PropertyValue[0]&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;load&nbsp;new&nbsp;calc&nbsp;file<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XComponent&nbsp;xSpreadsheetComponent&nbsp;=&nbsp;xComponentLoader.loadComponentFromURL(&quot;private&#x3a;factory&#x2f;scalc&quot;,&nbsp;&quot;_blank&quot;,&nbsp;0,&nbsp;loadProps)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;query&nbsp;its&nbsp;XSpreadsheetDocument&nbsp;interface,&nbsp;we&nbsp;want&nbsp;to&nbsp;use&nbsp;getSheets()<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XSpreadsheetDocument&nbsp;xSpreadsheetDocument&nbsp;=&nbsp;(XSpreadsheetDocument)UnoRuntime.queryInterface(XSpreadsheetDocument.class,&nbsp;xSpreadsheetComponent)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;use&nbsp;getSheets&nbsp;to&nbsp;get&nbsp;spreadsheets&nbsp;container<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XSpreadsheets&nbsp;xSpreadsheets&nbsp;=&nbsp;xSpreadsheetDocument.getSheets()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;insert&nbsp;new&nbsp;sheet&nbsp;at&nbsp;position&nbsp;0&nbsp;and&nbsp;get&nbsp;it&nbsp;by&nbsp;name,&nbsp;then&nbsp;query&nbsp;its&nbsp;XSpreadsheet&nbsp;interface<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xSpreadsheets.insertNewByName(&quot;MySheet&quot;,&nbsp;(short)0)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;sheet&nbsp;=&nbsp;xSpreadsheets.getByName(&quot;MySheet&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XSpreadsheet&nbsp;xSpreadsheet&nbsp;=&nbsp;(XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class,&nbsp;sheet)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;use&nbsp;XSpreadsheet&nbsp;interface&nbsp;to&nbsp;get&nbsp;the&nbsp;cell&nbsp;A1&nbsp;at&nbsp;position&nbsp;0,0&nbsp;and&nbsp;enter&nbsp;21&nbsp;as&nbsp;value<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XCell&nbsp;xCell&nbsp;=&nbsp;xSpreadsheet.getCellByPosition(0,&nbsp;0)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCell.setValue(21)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;enter&nbsp;another&nbsp;value&nbsp;into&nbsp;the&nbsp;cell&nbsp;A2&nbsp;at&nbsp;position&nbsp;0,1<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCell&nbsp;=&nbsp;xSpreadsheet.getCellByPosition(0,&nbsp;1)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCell.setValue(21)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;sum&nbsp;up&nbsp;the&nbsp;two&nbsp;cells<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCell&nbsp;=&nbsp;xSpreadsheet.getCellByPosition(0,&nbsp;2)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCell.setFormula(&quot;=sum(A1&#x3a;A2)&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;we&nbsp;want&nbsp;to&nbsp;access&nbsp;the&nbsp;cell&nbsp;property&nbsp;CellStyle,&nbsp;so&nbsp;query&nbsp;the&nbsp;cell&#8217;s&nbsp;XPropertySet&nbsp;interface<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XPropertySet&nbsp;xCellProps&nbsp;=&nbsp;(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,&nbsp;xCell)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;assign&nbsp;the&nbsp;cell&nbsp;style&nbsp;&quot;Result&quot;&nbsp;to&nbsp;our&nbsp;formula,&nbsp;which&nbsp;is&nbsp;available&nbsp;out&nbsp;of&nbsp;the&nbsp;box<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xCellProps.setPropertyValue(&quot;CellStyle&quot;,&nbsp;&quot;Result&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;we&nbsp;want&nbsp;to&nbsp;make&nbsp;our&nbsp;new&nbsp;sheet&nbsp;the&nbsp;current&nbsp;sheet,&nbsp;so&nbsp;we&nbsp;need&nbsp;to&nbsp;ask&nbsp;the&nbsp;model<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;for&nbsp;the&nbsp;controller&#x3a;&nbsp;first&nbsp;query&nbsp;the&nbsp;XModel&nbsp;interface&nbsp;from&nbsp;our&nbsp;spreadsheet&nbsp;component<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XModel&nbsp;xSpreadsheetModel&nbsp;=&nbsp;(XModel)UnoRuntime.queryInterface(XModel.class,&nbsp;xSpreadsheetComponent)&#x3b;<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;then&nbsp;get&nbsp;the&nbsp;current&nbsp;controller&nbsp;from&nbsp;the&nbsp;model<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XController&nbsp;xSpreadsheetController&nbsp;=&nbsp;xSpreadsheetModel.getCurrentController()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;get&nbsp;the&nbsp;XSpreadsheetView&nbsp;interface&nbsp;from&nbsp;the&nbsp;controller,&nbsp;we&nbsp;want&nbsp;to&nbsp;call&nbsp;its&nbsp;method<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;setActiveSheet<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XSpreadsheetView&nbsp;xSpreadsheetView&nbsp;=&nbsp;(XSpreadsheetView)UnoRuntime.queryInterface(XSpreadsheetView.class,&nbsp;xSpreadsheetController)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;make&nbsp;our&nbsp;newly&nbsp;inserted&nbsp;sheet&nbsp;the&nbsp;active&nbsp;sheet&nbsp;using&nbsp;setActiveSheet<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xSpreadsheetView.setActiveSheet(xSpreadsheet)&#x3b;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;catch(&nbsp;com.sun.star.lang.DisposedException&nbsp;e&nbsp;)&nbsp;{&nbsp;&#x2f;&#x2f;works&nbsp;from&nbsp;Patch&nbsp;1<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteContext&nbsp;=&nbsp;null&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;e&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;void&nbsp;useConnection()&nbsp;throws&nbsp;java.lang.Exception&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;service&nbsp;=&nbsp;&quot;uno&#x3a;socket,host=localhost,port=8100&#x3b;urp&#x3b;StarOffice.ServiceManager&quot;&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteServiceManager&nbsp;=&nbsp;this.getRemoteServiceManager(service)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;available&nbsp;=&nbsp;(null&nbsp;&#x21;=&nbsp;xRemoteServiceManager&nbsp;?&nbsp;&quot;available&quot;&nbsp;&#x3a;&nbsp;&quot;not&nbsp;available&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;remote&nbsp;ServiceManager&nbsp;is&nbsp;&quot;&nbsp;+&nbsp;available)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;do&nbsp;something&nbsp;with&nbsp;the&nbsp;service&nbsp;manager&#8230;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(com.sun.star.connection.NoConnectException&nbsp;e)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(&quot;No&nbsp;process&nbsp;listening&nbsp;on&nbsp;the&nbsp;resource&quot;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;e&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(com.sun.star.lang.DisposedException&nbsp;e)&nbsp;{&nbsp;&#x2f;&#x2f;works&nbsp;from&nbsp;Patch&nbsp;1<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteContext&nbsp;=&nbsp;null&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;e&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;XMultiComponentFactory&nbsp;getRemoteServiceManager(String&nbsp;unoUrl)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throws&nbsp;java.lang.Exception&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(xRemoteContext&nbsp;==&nbsp;null)&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;First&nbsp;step&#x3a;&nbsp;create&nbsp;local&nbsp;component&nbsp;context,&nbsp;get&nbsp;local&nbsp;servicemanager&nbsp;and<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;ask&nbsp;it&nbsp;to&nbsp;create&nbsp;a&nbsp;UnoUrlResolver&nbsp;object&nbsp;with&nbsp;an&nbsp;XUnoUrlResolver&nbsp;interface<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XComponentContext&nbsp;xLocalContext&nbsp;=<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XMultiComponentFactory&nbsp;xLocalServiceManager&nbsp;=&nbsp;xLocalContext.getServiceManager()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;urlResolver&nbsp;&nbsp;=&nbsp;xLocalServiceManager.createInstanceWithContext(&quot;com.sun.star.bridge.UnoUrlResolver&quot;,&nbsp;xLocalContext&nbsp;)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;query&nbsp;XUnoUrlResolver&nbsp;interface&nbsp;from&nbsp;urlResolver&nbsp;object<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XUnoUrlResolver&nbsp;xUnoUrlResolver&nbsp;=&nbsp;(XUnoUrlResolver)&nbsp;UnoRuntime.queryInterface(XUnoUrlResolver.class,&nbsp;urlResolver)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;Second&nbsp;step&#x3a;&nbsp;use&nbsp;xUrlResolver&nbsp;interface&nbsp;to&nbsp;import&nbsp;the&nbsp;remote&nbsp;StarOffice.ServiceManager,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2f;&#x2f;&nbsp;retrieve&nbsp;its&nbsp;property&nbsp;DefaultContext&nbsp;and&nbsp;get&nbsp;the&nbsp;remote&nbsp;servicemanager<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;initialObject&nbsp;=&nbsp;xUnoUrlResolver.resolve(unoUrl)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XPropertySet&nbsp;xPropertySet&nbsp;=&nbsp;(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,&nbsp;initialObject)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;context&nbsp;=&nbsp;xPropertySet.getPropertyValue(&quot;DefaultContext&quot;)&#x3b;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xRemoteContext&nbsp;=&nbsp;(XComponentContext)UnoRuntime.queryInterface(XComponentContext.class,&nbsp;context)&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;xRemoteContext.getServiceManager()&#x3b;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n}\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>OpenOffice\u306fUNO(Universal Network Objects)\u3092\u4f7f\u7528\u3057\u3066API\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3002 OpenOffice.org for Developers\u306e[SDK]-[SDK Download (1 &hellip; <a href=\"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/859.html\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-859","post","type-post","status-publish","format-standard","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=859"}],"version-history":[{"count":1,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/859\/revisions"}],"predecessor-version":[{"id":3162,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/859\/revisions\/3162"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}