1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir //*************************************************************************** 36*cdf0e10cSrcweir // comment: Step 1: bootstrap UNO and get the remote component context 37*cdf0e10cSrcweir // Step 2: open an empty text document 38*cdf0e10cSrcweir // Step 3: enter some text 39*cdf0e10cSrcweir // Step 4: insert a text table 40*cdf0e10cSrcweir // Step 5: insert colored text 41*cdf0e10cSrcweir // Step 6: insert a text frame 42*cdf0e10cSrcweir //*************************************************************************** 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir public class SWriter { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir public static void main(String args[]) { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooo 52*cdf0e10cSrcweir // bootstrap UNO and get the remote component context. The context can 53*cdf0e10cSrcweir // be used to get the service manager 54*cdf0e10cSrcweir //************************************************************************* 55*cdf0e10cSrcweir com.sun.star.uno.XComponentContext xContext = null; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir try { 58*cdf0e10cSrcweir // get the remote office component context 59*cdf0e10cSrcweir xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 60*cdf0e10cSrcweir if( xContext != null ) 61*cdf0e10cSrcweir System.out.println("Connected to a running office ..."); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir catch( Exception e) { 64*cdf0e10cSrcweir e.printStackTrace(System.err); 65*cdf0e10cSrcweir System.exit(1); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooo 69*cdf0e10cSrcweir // open an empty document. In this case it's a writer document. 70*cdf0e10cSrcweir // For this purpose an instance of com.sun.star.frame.Desktop 71*cdf0e10cSrcweir // is created. It's interface XDesktop provides the XComponentLoader, 72*cdf0e10cSrcweir // which is used to open the document via loadComponentFromURL 73*cdf0e10cSrcweir //************************************************************************* 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir //Open Writer document 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir System.out.println("Opening an empty Writer document"); 78*cdf0e10cSrcweir com.sun.star.text.XTextDocument myDoc = openWriter(xContext); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir //************************************************************************* 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooo 84*cdf0e10cSrcweir // insert some text. 85*cdf0e10cSrcweir // For this purpose get the Text-Object of the document an create the 86*cdf0e10cSrcweir // cursor. Now it is possible to insert a text at the cursor-position 87*cdf0e10cSrcweir // via insertString 88*cdf0e10cSrcweir //************************************************************************* 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //getting the text object 92*cdf0e10cSrcweir com.sun.star.text.XText xText = myDoc.getText(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //create a cursor object 95*cdf0e10cSrcweir com.sun.star.text.XTextCursor xTCursor = xText.createTextCursor(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //inserting some Text 98*cdf0e10cSrcweir xText.insertString( xTCursor, "The first line in the newly created text document.\n", false ); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //inserting a second line 101*cdf0e10cSrcweir xText.insertString( xTCursor, "Now we're in the second line\n", false ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //************************************************************************* 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooo 107*cdf0e10cSrcweir // insert a text table. 108*cdf0e10cSrcweir // For this purpose get MultiServiceFactory of the document, create an 109*cdf0e10cSrcweir // instance of com.sun.star.text.TextTable and initialize it. Now it can 110*cdf0e10cSrcweir // be inserted at the cursor position via insertTextContent. 111*cdf0e10cSrcweir // After that some properties are changed and some data is inserted. 112*cdf0e10cSrcweir //************************************************************************* 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //inserting a text table 115*cdf0e10cSrcweir System.out.println("Inserting a text table"); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir //getting MSF of the document 118*cdf0e10cSrcweir com.sun.star.lang.XMultiServiceFactory xDocMSF = 119*cdf0e10cSrcweir (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface( 120*cdf0e10cSrcweir com.sun.star.lang.XMultiServiceFactory.class, myDoc); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //create instance of a text table 123*cdf0e10cSrcweir com.sun.star.text.XTextTable xTT = null; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir try { 126*cdf0e10cSrcweir Object oInt = xDocMSF.createInstance("com.sun.star.text.TextTable"); 127*cdf0e10cSrcweir xTT = (com.sun.star.text.XTextTable) 128*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt); 129*cdf0e10cSrcweir } catch (Exception e) { 130*cdf0e10cSrcweir System.err.println("Couldn't create instance "+ e); 131*cdf0e10cSrcweir e.printStackTrace(System.err); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //initialize the text table with 4 columns an 4 rows 135*cdf0e10cSrcweir xTT.initialize(4,4); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xTTRowPS = null; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //insert the table 140*cdf0e10cSrcweir try { 141*cdf0e10cSrcweir xText.insertTextContent(xTCursor, xTT, false); 142*cdf0e10cSrcweir // get first Row 143*cdf0e10cSrcweir com.sun.star.container.XIndexAccess xTTRows = xTT.getRows(); 144*cdf0e10cSrcweir xTTRowPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( 145*cdf0e10cSrcweir com.sun.star.beans.XPropertySet.class, xTTRows.getByIndex(0)); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir } catch (Exception e) { 148*cdf0e10cSrcweir System.err.println("Couldn't insert the table " + e); 149*cdf0e10cSrcweir e.printStackTrace(System.err); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // get the property set of the text table 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xTTPS = (com.sun.star.beans.XPropertySet) 156*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // Change the BackColor 159*cdf0e10cSrcweir try { 160*cdf0e10cSrcweir xTTPS.setPropertyValue("BackTransparent", new Boolean(false)); 161*cdf0e10cSrcweir xTTPS.setPropertyValue("BackColor",new Integer(13421823)); 162*cdf0e10cSrcweir xTTRowPS.setPropertyValue("BackTransparent", new Boolean(false)); 163*cdf0e10cSrcweir xTTRowPS.setPropertyValue("BackColor",new Integer(6710932)); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir } catch (Exception e) { 166*cdf0e10cSrcweir System.err.println("Couldn't change the color " + e); 167*cdf0e10cSrcweir e.printStackTrace(System.err); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // write Text in the Table headers 171*cdf0e10cSrcweir System.out.println("Write text in the table headers"); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir insertIntoCell("A1","FirstColumn", xTT); 174*cdf0e10cSrcweir insertIntoCell("B1","SecondColumn", xTT) ; 175*cdf0e10cSrcweir insertIntoCell("C1","ThirdColumn", xTT) ; 176*cdf0e10cSrcweir insertIntoCell("D1","SUM", xTT) ; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //Insert Something in the text table 180*cdf0e10cSrcweir System.out.println("Insert something in the text table"); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir (xTT.getCellByName("A2")).setValue(22.5); 183*cdf0e10cSrcweir (xTT.getCellByName("B2")).setValue(5615.3); 184*cdf0e10cSrcweir (xTT.getCellByName("C2")).setValue(-2315.7); 185*cdf0e10cSrcweir (xTT.getCellByName("D2")).setFormula("sum <A2:C2>"); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir (xTT.getCellByName("A3")).setValue(21.5); 188*cdf0e10cSrcweir (xTT.getCellByName("B3")).setValue(615.3); 189*cdf0e10cSrcweir (xTT.getCellByName("C3")).setValue(-315.7); 190*cdf0e10cSrcweir (xTT.getCellByName("D3")).setFormula("sum <A3:C3>"); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir (xTT.getCellByName("A4")).setValue(121.5); 193*cdf0e10cSrcweir (xTT.getCellByName("B4")).setValue(-615.3); 194*cdf0e10cSrcweir (xTT.getCellByName("C4")).setValue(415.7); 195*cdf0e10cSrcweir (xTT.getCellByName("D4")).setFormula("sum <A4:C4>"); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooo 199*cdf0e10cSrcweir // insert a colored text. 200*cdf0e10cSrcweir // Get the propertySet of the cursor, change the CharColor and add a 201*cdf0e10cSrcweir // shadow. Then insert the Text via InsertString at the cursor position. 202*cdf0e10cSrcweir //************************************************************************* 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // get the property set of the cursor 205*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xTCPS = (com.sun.star.beans.XPropertySet) 206*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, 207*cdf0e10cSrcweir xTCursor); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir Object oldValue = null; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // Change the CharColor and add a Shadow 212*cdf0e10cSrcweir try { 213*cdf0e10cSrcweir xTCPS.setPropertyValue("CharColor",new Integer(255)); 214*cdf0e10cSrcweir xTCPS.setPropertyValue("CharShadowed", new Boolean(true)); 215*cdf0e10cSrcweir } catch (Exception e) { 216*cdf0e10cSrcweir System.err.println("Couldn't change the color " + e); 217*cdf0e10cSrcweir e.printStackTrace(System.err); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir //create a paragraph break 221*cdf0e10cSrcweir try { 222*cdf0e10cSrcweir xText.insertControlCharacter(xTCursor, 223*cdf0e10cSrcweir com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir } catch (Exception e) { 226*cdf0e10cSrcweir System.err.println("Couldn't insert break "+ e); 227*cdf0e10cSrcweir e.printStackTrace(System.err); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //inserting colored Text 231*cdf0e10cSrcweir System.out.println("Inserting colored Text"); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir xText.insertString(xTCursor, " This is a colored Text - blue with shadow\n", 234*cdf0e10cSrcweir false ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir //create a paragraph break 237*cdf0e10cSrcweir try { 238*cdf0e10cSrcweir xText.insertControlCharacter(xTCursor, 239*cdf0e10cSrcweir com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir } catch (Exception e) { 242*cdf0e10cSrcweir System.err.println("Couldn't insert break "+ e); 243*cdf0e10cSrcweir e.printStackTrace(System.err); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooo 247*cdf0e10cSrcweir // insert a text frame. 248*cdf0e10cSrcweir // create an instance of com.sun.star.text.TextFrame using the MSF of the 249*cdf0e10cSrcweir // document. Change some properties an insert it. 250*cdf0e10cSrcweir // Now get the text-Object of the frame an the corresponding cursor. 251*cdf0e10cSrcweir // Insert some text via insertString. 252*cdf0e10cSrcweir //************************************************************************* 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // Create a TextFrame 255*cdf0e10cSrcweir com.sun.star.text.XTextFrame xTF = null; 256*cdf0e10cSrcweir com.sun.star.drawing.XShape xTFS = null; 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir try { 259*cdf0e10cSrcweir Object oInt = xDocMSF.createInstance("com.sun.star.text.TextFrame"); 260*cdf0e10cSrcweir xTF = (com.sun.star.text.XTextFrame) UnoRuntime.queryInterface( 261*cdf0e10cSrcweir com.sun.star.text.XTextFrame.class,oInt); 262*cdf0e10cSrcweir xTFS = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface( 263*cdf0e10cSrcweir com.sun.star.drawing.XShape.class,oInt); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir com.sun.star.awt.Size aSize = new com.sun.star.awt.Size(); 266*cdf0e10cSrcweir aSize.Height = 400; 267*cdf0e10cSrcweir aSize.Width = 15000; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir xTFS.setSize(aSize); 270*cdf0e10cSrcweir } catch (Exception e) { 271*cdf0e10cSrcweir System.err.println("Couldn't create instance "+ e); 272*cdf0e10cSrcweir e.printStackTrace(System.err); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // get the property set of the text frame 276*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xTFPS = (com.sun.star.beans.XPropertySet) 277*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir // Change the AnchorType 280*cdf0e10cSrcweir try { 281*cdf0e10cSrcweir xTFPS.setPropertyValue("AnchorType", 282*cdf0e10cSrcweir com.sun.star.text.TextContentAnchorType.AS_CHARACTER); 283*cdf0e10cSrcweir } catch (Exception e) { 284*cdf0e10cSrcweir System.err.println("Couldn't change the color " + e); 285*cdf0e10cSrcweir e.printStackTrace(System.err); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir //insert the frame 289*cdf0e10cSrcweir System.out.println("Insert the text frame"); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir try { 292*cdf0e10cSrcweir xText.insertTextContent(xTCursor, xTF, false); 293*cdf0e10cSrcweir } catch (Exception e) { 294*cdf0e10cSrcweir System.err.println("Couldn't insert the frame " + e); 295*cdf0e10cSrcweir e.printStackTrace(System.err); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir //getting the text object of Frame 299*cdf0e10cSrcweir com.sun.star.text.XText xTextF = xTF.getText(); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir //create a cursor object 302*cdf0e10cSrcweir com.sun.star.text.XTextCursor xTCF = xTextF.createTextCursor(); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //inserting some Text 305*cdf0e10cSrcweir xTextF.insertString(xTCF, 306*cdf0e10cSrcweir "The first line in the newly created text frame.", false); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir xTextF.insertString(xTCF, 310*cdf0e10cSrcweir "\nWith this second line the height of the frame raises.", false); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir //insert a paragraph break 313*cdf0e10cSrcweir try { 314*cdf0e10cSrcweir xText.insertControlCharacter(xTCursor, 315*cdf0e10cSrcweir com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false ); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir } catch (Exception e) { 318*cdf0e10cSrcweir System.err.println("Couldn't insert break "+ e); 319*cdf0e10cSrcweir e.printStackTrace(System.err); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // Change the CharColor and add a Shadow 323*cdf0e10cSrcweir try { 324*cdf0e10cSrcweir xTCPS.setPropertyValue("CharColor",new Integer(65536)); 325*cdf0e10cSrcweir xTCPS.setPropertyValue("CharShadowed", new Boolean(false)); 326*cdf0e10cSrcweir } catch (Exception e) { 327*cdf0e10cSrcweir System.err.println("Couldn't change the color " + e); 328*cdf0e10cSrcweir e.printStackTrace(System.err); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir xText.insertString(xTCursor, " That's all for now !!", false ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir System.out.println("done"); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir System.exit(0); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir public static com.sun.star.text.XTextDocument openWriter( 340*cdf0e10cSrcweir com.sun.star.uno.XComponentContext xContext) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir //define variables 343*cdf0e10cSrcweir com.sun.star.frame.XComponentLoader xCLoader; 344*cdf0e10cSrcweir com.sun.star.text.XTextDocument xDoc = null; 345*cdf0e10cSrcweir com.sun.star.lang.XComponent xComp = null; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir try { 348*cdf0e10cSrcweir // get the remote office service manager 349*cdf0e10cSrcweir com.sun.star.lang.XMultiComponentFactory xMCF = 350*cdf0e10cSrcweir xContext.getServiceManager(); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir Object oDesktop = xMCF.createInstanceWithContext( 353*cdf0e10cSrcweir "com.sun.star.frame.Desktop", xContext); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir xCLoader = (com.sun.star.frame.XComponentLoader) 356*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, 357*cdf0e10cSrcweir oDesktop); 358*cdf0e10cSrcweir com.sun.star.beans.PropertyValue [] szEmptyArgs = 359*cdf0e10cSrcweir new com.sun.star.beans.PropertyValue [0]; 360*cdf0e10cSrcweir String strDoc = "private:factory/swriter"; 361*cdf0e10cSrcweir xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs); 362*cdf0e10cSrcweir xDoc = (com.sun.star.text.XTextDocument) 363*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, 364*cdf0e10cSrcweir xComp); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir } catch(Exception e){ 367*cdf0e10cSrcweir System.err.println(" Exception " + e); 368*cdf0e10cSrcweir e.printStackTrace(System.err); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir return xDoc; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir public static void insertIntoCell(String CellName, String theText, 374*cdf0e10cSrcweir com.sun.star.text.XTextTable xTTbl) { 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir com.sun.star.text.XText xTableText = (com.sun.star.text.XText) 377*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.text.XText.class, 378*cdf0e10cSrcweir xTTbl.getCellByName(CellName)); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //create a cursor object 381*cdf0e10cSrcweir com.sun.star.text.XTextCursor xTC = xTableText.createTextCursor(); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xTPS = (com.sun.star.beans.XPropertySet) 384*cdf0e10cSrcweir UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir try { 387*cdf0e10cSrcweir xTPS.setPropertyValue("CharColor",new Integer(16777215)); 388*cdf0e10cSrcweir } catch (Exception e) { 389*cdf0e10cSrcweir System.err.println(" Exception " + e); 390*cdf0e10cSrcweir e.printStackTrace(System.err); 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir //inserting some Text 394*cdf0e10cSrcweir xTableText.setString( theText ); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir } 398