xref: /trunk/main/odk/examples/java/Text/SWriter.java (revision 34dd1e25)
1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //***************************************************************************
25cdf0e10cSrcweir // comment: Step 1: bootstrap UNO and get the remote component context
26cdf0e10cSrcweir //          Step 2: open an empty text document
27cdf0e10cSrcweir //          Step 3: enter some text
28cdf0e10cSrcweir //          Step 4: insert a text table
29cdf0e10cSrcweir //          Step 5: insert colored text
30cdf0e10cSrcweir //          Step 6: insert a text frame
31cdf0e10cSrcweir //***************************************************************************
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir public class SWriter  {
36cdf0e10cSrcweir 
main(String args[])37cdf0e10cSrcweir     public static void main(String args[]) {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooo
41cdf0e10cSrcweir         // bootstrap UNO and get the remote component context. The context can
42cdf0e10cSrcweir         // be used to get the service manager
43cdf0e10cSrcweir         //*************************************************************************
44cdf0e10cSrcweir         com.sun.star.uno.XComponentContext xContext = null;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir         try {
47cdf0e10cSrcweir             // get the remote office component context
48cdf0e10cSrcweir             xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
49cdf0e10cSrcweir             if( xContext != null )
50cdf0e10cSrcweir                 System.out.println("Connected to a running office ...");
51cdf0e10cSrcweir         }
52cdf0e10cSrcweir         catch( Exception e) {
53cdf0e10cSrcweir             e.printStackTrace(System.err);
54cdf0e10cSrcweir             System.exit(1);
55cdf0e10cSrcweir         }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooo
58cdf0e10cSrcweir         // open an empty document. In this case it's a writer document.
59cdf0e10cSrcweir         // For this purpose an instance of com.sun.star.frame.Desktop
60cdf0e10cSrcweir         // is created. It's interface XDesktop provides the XComponentLoader,
61cdf0e10cSrcweir         // which is used to open the document via loadComponentFromURL
62cdf0e10cSrcweir         //*************************************************************************
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         //Open Writer document
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         System.out.println("Opening an empty Writer document");
67cdf0e10cSrcweir         com.sun.star.text.XTextDocument myDoc = openWriter(xContext);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         //*************************************************************************
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooo
73cdf0e10cSrcweir         // insert some text.
74cdf0e10cSrcweir         // For this purpose get the Text-Object of the document an create the
75cdf0e10cSrcweir         // cursor. Now it is possible to insert a text at the cursor-position
76cdf0e10cSrcweir         // via insertString
77cdf0e10cSrcweir         //*************************************************************************
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         //getting the text object
81cdf0e10cSrcweir         com.sun.star.text.XText xText = myDoc.getText();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         //create a cursor object
84cdf0e10cSrcweir         com.sun.star.text.XTextCursor xTCursor = xText.createTextCursor();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         //inserting some Text
87cdf0e10cSrcweir         xText.insertString( xTCursor, "The first line in the newly created text document.\n", false );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         //inserting a second line
90cdf0e10cSrcweir         xText.insertString( xTCursor, "Now we're in the second line\n", false );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         //*************************************************************************
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooo
96cdf0e10cSrcweir         // insert a text table.
97cdf0e10cSrcweir         // For this purpose get MultiServiceFactory of the document, create an
98cdf0e10cSrcweir         // instance of com.sun.star.text.TextTable and initialize it. Now it can
99cdf0e10cSrcweir         // be inserted at the cursor position via insertTextContent.
100cdf0e10cSrcweir         // After that some properties are changed and some data is inserted.
101cdf0e10cSrcweir         //*************************************************************************
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         //inserting a text table
104cdf0e10cSrcweir         System.out.println("Inserting a text table");
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         //getting MSF of the document
107cdf0e10cSrcweir         com.sun.star.lang.XMultiServiceFactory xDocMSF =
108cdf0e10cSrcweir             (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(
109cdf0e10cSrcweir                 com.sun.star.lang.XMultiServiceFactory.class, myDoc);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         //create instance of a text table
112cdf0e10cSrcweir         com.sun.star.text.XTextTable xTT = null;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         try {
115cdf0e10cSrcweir             Object oInt = xDocMSF.createInstance("com.sun.star.text.TextTable");
116cdf0e10cSrcweir             xTT = (com.sun.star.text.XTextTable)
117cdf0e10cSrcweir                 UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt);
118cdf0e10cSrcweir         } catch (Exception e) {
119cdf0e10cSrcweir             System.err.println("Couldn't create instance "+ e);
120cdf0e10cSrcweir             e.printStackTrace(System.err);
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         //initialize the text table with 4 columns an 4 rows
124cdf0e10cSrcweir         xTT.initialize(4,4);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         com.sun.star.beans.XPropertySet xTTRowPS = null;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         //insert the table
129cdf0e10cSrcweir         try {
130cdf0e10cSrcweir             xText.insertTextContent(xTCursor, xTT, false);
131cdf0e10cSrcweir             // get first Row
132cdf0e10cSrcweir             com.sun.star.container.XIndexAccess xTTRows = xTT.getRows();
133cdf0e10cSrcweir             xTTRowPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
134cdf0e10cSrcweir                 com.sun.star.beans.XPropertySet.class, xTTRows.getByIndex(0));
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         } catch (Exception e) {
137cdf0e10cSrcweir             System.err.println("Couldn't insert the table " + e);
138cdf0e10cSrcweir             e.printStackTrace(System.err);
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         // get the property set of the text table
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         com.sun.star.beans.XPropertySet xTTPS = (com.sun.star.beans.XPropertySet)
145cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         // Change the BackColor
148cdf0e10cSrcweir         try {
149cdf0e10cSrcweir             xTTPS.setPropertyValue("BackTransparent", new Boolean(false));
150cdf0e10cSrcweir             xTTPS.setPropertyValue("BackColor",new Integer(13421823));
151cdf0e10cSrcweir             xTTRowPS.setPropertyValue("BackTransparent", new Boolean(false));
152cdf0e10cSrcweir             xTTRowPS.setPropertyValue("BackColor",new Integer(6710932));
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         } catch (Exception e) {
155cdf0e10cSrcweir             System.err.println("Couldn't change the color " + e);
156cdf0e10cSrcweir             e.printStackTrace(System.err);
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         // write Text in the Table headers
160cdf0e10cSrcweir         System.out.println("Write text in the table headers");
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         insertIntoCell("A1","FirstColumn", xTT);
163cdf0e10cSrcweir         insertIntoCell("B1","SecondColumn", xTT) ;
164cdf0e10cSrcweir         insertIntoCell("C1","ThirdColumn", xTT) ;
165cdf0e10cSrcweir         insertIntoCell("D1","SUM", xTT) ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         //Insert Something in the text table
169cdf0e10cSrcweir         System.out.println("Insert something in the text table");
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         (xTT.getCellByName("A2")).setValue(22.5);
172cdf0e10cSrcweir         (xTT.getCellByName("B2")).setValue(5615.3);
173cdf0e10cSrcweir         (xTT.getCellByName("C2")).setValue(-2315.7);
174cdf0e10cSrcweir         (xTT.getCellByName("D2")).setFormula("sum <A2:C2>");
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         (xTT.getCellByName("A3")).setValue(21.5);
177cdf0e10cSrcweir         (xTT.getCellByName("B3")).setValue(615.3);
178cdf0e10cSrcweir         (xTT.getCellByName("C3")).setValue(-315.7);
179cdf0e10cSrcweir         (xTT.getCellByName("D3")).setFormula("sum <A3:C3>");
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         (xTT.getCellByName("A4")).setValue(121.5);
182cdf0e10cSrcweir         (xTT.getCellByName("B4")).setValue(-615.3);
183cdf0e10cSrcweir         (xTT.getCellByName("C4")).setValue(415.7);
184cdf0e10cSrcweir         (xTT.getCellByName("D4")).setFormula("sum <A4:C4>");
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooo
188cdf0e10cSrcweir         // insert a colored text.
189cdf0e10cSrcweir         // Get the propertySet of the cursor, change the CharColor and add a
190cdf0e10cSrcweir         // shadow. Then insert the Text via InsertString at the cursor position.
191cdf0e10cSrcweir         //*************************************************************************
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         // get the property set of the cursor
194cdf0e10cSrcweir         com.sun.star.beans.XPropertySet xTCPS = (com.sun.star.beans.XPropertySet)
195cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
196cdf0e10cSrcweir                                       xTCursor);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         Object oldValue = null;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         // Change the CharColor and add a Shadow
201cdf0e10cSrcweir         try {
202cdf0e10cSrcweir             xTCPS.setPropertyValue("CharColor",new Integer(255));
203cdf0e10cSrcweir             xTCPS.setPropertyValue("CharShadowed", new Boolean(true));
204cdf0e10cSrcweir         } catch (Exception e) {
205cdf0e10cSrcweir             System.err.println("Couldn't change the color " + e);
206cdf0e10cSrcweir             e.printStackTrace(System.err);
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         //create a paragraph break
210cdf0e10cSrcweir         try {
211cdf0e10cSrcweir             xText.insertControlCharacter(xTCursor,
212cdf0e10cSrcweir                       com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         } catch (Exception e) {
215cdf0e10cSrcweir             System.err.println("Couldn't insert break "+ e);
216cdf0e10cSrcweir             e.printStackTrace(System.err);
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         //inserting colored Text
220cdf0e10cSrcweir         System.out.println("Inserting colored Text");
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         xText.insertString(xTCursor, " This is a colored Text - blue with shadow\n",
223cdf0e10cSrcweir                            false );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         //create a paragraph break
226cdf0e10cSrcweir         try {
227cdf0e10cSrcweir             xText.insertControlCharacter(xTCursor,
228cdf0e10cSrcweir                       com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         } catch (Exception e) {
231cdf0e10cSrcweir             System.err.println("Couldn't insert break "+ e);
232cdf0e10cSrcweir             e.printStackTrace(System.err);
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooo
236cdf0e10cSrcweir         // insert a text frame.
237cdf0e10cSrcweir         // create an instance of com.sun.star.text.TextFrame using the MSF of the
238cdf0e10cSrcweir         // document. Change some properties an insert it.
239cdf0e10cSrcweir         // Now get the text-Object of the frame an the corresponding cursor.
240cdf0e10cSrcweir         // Insert some text via insertString.
241cdf0e10cSrcweir         //*************************************************************************
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         // Create a TextFrame
244cdf0e10cSrcweir         com.sun.star.text.XTextFrame xTF = null;
245cdf0e10cSrcweir         com.sun.star.drawing.XShape xTFS = null;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         try {
248cdf0e10cSrcweir             Object oInt = xDocMSF.createInstance("com.sun.star.text.TextFrame");
249cdf0e10cSrcweir             xTF = (com.sun.star.text.XTextFrame) UnoRuntime.queryInterface(
250cdf0e10cSrcweir                 com.sun.star.text.XTextFrame.class,oInt);
251cdf0e10cSrcweir             xTFS = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface(
252cdf0e10cSrcweir                 com.sun.star.drawing.XShape.class,oInt);
253cdf0e10cSrcweir 
254cdf0e10cSrcweir             com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
255cdf0e10cSrcweir             aSize.Height = 400;
256cdf0e10cSrcweir             aSize.Width = 15000;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             xTFS.setSize(aSize);
259cdf0e10cSrcweir         } catch (Exception e) {
260cdf0e10cSrcweir             System.err.println("Couldn't create instance "+ e);
261cdf0e10cSrcweir             e.printStackTrace(System.err);
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         // get the property set of the text frame
265cdf0e10cSrcweir         com.sun.star.beans.XPropertySet xTFPS = (com.sun.star.beans.XPropertySet)
266cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF);
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         // Change the AnchorType
269cdf0e10cSrcweir         try {
270cdf0e10cSrcweir             xTFPS.setPropertyValue("AnchorType",
271cdf0e10cSrcweir                       com.sun.star.text.TextContentAnchorType.AS_CHARACTER);
272cdf0e10cSrcweir         } catch (Exception e) {
273cdf0e10cSrcweir             System.err.println("Couldn't change the color " + e);
274cdf0e10cSrcweir             e.printStackTrace(System.err);
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         //insert the frame
278cdf0e10cSrcweir         System.out.println("Insert the text frame");
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         try {
281cdf0e10cSrcweir             xText.insertTextContent(xTCursor, xTF, false);
282cdf0e10cSrcweir         } catch (Exception e) {
283cdf0e10cSrcweir             System.err.println("Couldn't insert the frame " + e);
284cdf0e10cSrcweir             e.printStackTrace(System.err);
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         //getting the text object of Frame
288cdf0e10cSrcweir         com.sun.star.text.XText xTextF = xTF.getText();
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         //create a cursor object
291cdf0e10cSrcweir         com.sun.star.text.XTextCursor xTCF = xTextF.createTextCursor();
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         //inserting some Text
294cdf0e10cSrcweir         xTextF.insertString(xTCF,
295cdf0e10cSrcweir                  "The first line in the newly created text frame.", false);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         xTextF.insertString(xTCF,
299cdf0e10cSrcweir                  "\nWith this second line the height of the frame raises.", false);
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         //insert a paragraph break
302cdf0e10cSrcweir         try {
303cdf0e10cSrcweir             xText.insertControlCharacter(xTCursor,
304cdf0e10cSrcweir                       com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir         } catch (Exception e) {
307cdf0e10cSrcweir             System.err.println("Couldn't insert break "+ e);
308cdf0e10cSrcweir             e.printStackTrace(System.err);
309cdf0e10cSrcweir         }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         // Change the CharColor and add a Shadow
312cdf0e10cSrcweir         try {
313cdf0e10cSrcweir             xTCPS.setPropertyValue("CharColor",new Integer(65536));
314cdf0e10cSrcweir             xTCPS.setPropertyValue("CharShadowed", new Boolean(false));
315cdf0e10cSrcweir         } catch (Exception e) {
316cdf0e10cSrcweir             System.err.println("Couldn't change the color " + e);
317cdf0e10cSrcweir             e.printStackTrace(System.err);
318cdf0e10cSrcweir         }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         xText.insertString(xTCursor, " That's all for now !!", false );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir         System.out.println("done");
323cdf0e10cSrcweir 
324cdf0e10cSrcweir         System.exit(0);
325cdf0e10cSrcweir     }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 
openWriter( com.sun.star.uno.XComponentContext xContext)328cdf0e10cSrcweir     public static com.sun.star.text.XTextDocument openWriter(
329cdf0e10cSrcweir         com.sun.star.uno.XComponentContext xContext)
330cdf0e10cSrcweir     {
331cdf0e10cSrcweir         //define variables
332cdf0e10cSrcweir         com.sun.star.frame.XComponentLoader xCLoader;
333cdf0e10cSrcweir         com.sun.star.text.XTextDocument xDoc = null;
334cdf0e10cSrcweir         com.sun.star.lang.XComponent xComp = null;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         try {
337cdf0e10cSrcweir             // get the remote office service manager
338cdf0e10cSrcweir             com.sun.star.lang.XMultiComponentFactory xMCF =
339cdf0e10cSrcweir                 xContext.getServiceManager();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir             Object oDesktop = xMCF.createInstanceWithContext(
342cdf0e10cSrcweir                                         "com.sun.star.frame.Desktop", xContext);
343cdf0e10cSrcweir 
344cdf0e10cSrcweir             xCLoader = (com.sun.star.frame.XComponentLoader)
345cdf0e10cSrcweir                 UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
346cdf0e10cSrcweir                                           oDesktop);
347cdf0e10cSrcweir             com.sun.star.beans.PropertyValue [] szEmptyArgs =
348cdf0e10cSrcweir                 new com.sun.star.beans.PropertyValue [0];
349cdf0e10cSrcweir             String strDoc = "private:factory/swriter";
350cdf0e10cSrcweir             xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
351cdf0e10cSrcweir             xDoc = (com.sun.star.text.XTextDocument)
352cdf0e10cSrcweir                 UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
353cdf0e10cSrcweir                                           xComp);
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         } catch(Exception e){
356cdf0e10cSrcweir             System.err.println(" Exception " + e);
357cdf0e10cSrcweir             e.printStackTrace(System.err);
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         return xDoc;
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
insertIntoCell(String CellName, String theText, com.sun.star.text.XTextTable xTTbl)362cdf0e10cSrcweir     public static void insertIntoCell(String CellName, String theText,
363cdf0e10cSrcweir                                       com.sun.star.text.XTextTable xTTbl) {
364cdf0e10cSrcweir 
365cdf0e10cSrcweir         com.sun.star.text.XText xTableText = (com.sun.star.text.XText)
366cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.text.XText.class,
367cdf0e10cSrcweir                                       xTTbl.getCellByName(CellName));
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         //create a cursor object
370cdf0e10cSrcweir         com.sun.star.text.XTextCursor xTC = xTableText.createTextCursor();
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         com.sun.star.beans.XPropertySet xTPS = (com.sun.star.beans.XPropertySet)
373cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
374cdf0e10cSrcweir 
375cdf0e10cSrcweir         try {
376cdf0e10cSrcweir             xTPS.setPropertyValue("CharColor",new Integer(16777215));
377cdf0e10cSrcweir         } catch (Exception e) {
378cdf0e10cSrcweir             System.err.println(" Exception " + e);
379cdf0e10cSrcweir             e.printStackTrace(System.err);
380cdf0e10cSrcweir         }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir         //inserting some Text
383cdf0e10cSrcweir         xTableText.setString( theText );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir }
387