swriter.py (bd8ef897) | swriter.py (d47d317b) |
---|---|
1# ************************************************************* | 1# ************************************************************* |
2# | 2# |
3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at | 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at |
10# | 10# |
11# http://www.apache.org/licenses/LICENSE-2.0 | 11# http://www.apache.org/licenses/LICENSE-2.0 |
12# | 12# |
13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. | 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. |
19# | 19# |
20# ************************************************************* 21 22 | 20# ************************************************************* 21 22 |
23# bootstrap uno component context | 23# bootstrap uno component context |
24import uno 25import unohelper 26 27 28# a UNO struct later needed to create a document 29from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK 30from com.sun.star.text.TextContentAnchorType import AS_CHARACTER 31from com.sun.star.awt import Size 32 33 34def insertTextIntoCell( table, cellName, text, color ): 35 tableText = table.getCellByName( cellName ) 36 cursor = tableText.createTextCursor() 37 cursor.setPropertyValue( "CharColor", color ) 38 tableText.setString( text ) 39 40localContext = uno.getComponentContext() | 24import uno 25import unohelper 26 27 28# a UNO struct later needed to create a document 29from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK 30from com.sun.star.text.TextContentAnchorType import AS_CHARACTER 31from com.sun.star.awt import Size 32 33 34def insertTextIntoCell( table, cellName, text, color ): 35 tableText = table.getCellByName( cellName ) 36 cursor = tableText.createTextCursor() 37 cursor.setPropertyValue( "CharColor", color ) 38 tableText.setString( text ) 39 40localContext = uno.getComponentContext() |
41 | 41 |
42resolver = localContext.ServiceManager.createInstanceWithContext( 43 "com.sun.star.bridge.UnoUrlResolver", localContext ) 44 45smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" ) 46remoteContext = smgr.getPropertyValue( "DefaultContext" ) 47 48#remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) 49#smgr = remoteContext.ServiceManager 50 51desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext) 52 53# open a writer document 54doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) 55 56text = doc.Text 57cursor = text.createTextCursor() 58text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) | 42resolver = localContext.ServiceManager.createInstanceWithContext( 43 "com.sun.star.bridge.UnoUrlResolver", localContext ) 44 45smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" ) 46remoteContext = smgr.getPropertyValue( "DefaultContext" ) 47 48#remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) 49#smgr = remoteContext.ServiceManager 50 51desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext) 52 53# open a writer document 54doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) 55 56text = doc.Text 57cursor = text.createTextCursor() 58text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) |
59text.insertString( cursor, "Now we are in the second line\n" , 0 ) | 59text.insertString( cursor, "Now we are in the second line.\n" , 0 ) |
60 61# create a text table 62table = doc.createInstance( "com.sun.star.text.TextTable" ) 63 64# with 4 rows and 4 columns 65table.initialize( 4,4) 66 67text.insertTextContent( cursor, table, 0 ) --- 30 unchanged lines hidden (view full) --- 98table.getCellByName("C4").setValue(415.7) 99table.getCellByName("D4").setFormula("sum <A4:C4>") 100 101 102cursor.setPropertyValue( "CharColor", 255 ) 103cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) 104 105text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) | 60 61# create a text table 62table = doc.createInstance( "com.sun.star.text.TextTable" ) 63 64# with 4 rows and 4 columns 65table.initialize( 4,4) 66 67text.insertTextContent( cursor, table, 0 ) --- 30 unchanged lines hidden (view full) --- 98table.getCellByName("C4").setValue(415.7) 99table.getCellByName("D4").setFormula("sum <A4:C4>") 100 101 102cursor.setPropertyValue( "CharColor", 255 ) 103cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) 104 105text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) |
106text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 ) | 106text.insertString( cursor, " This is a colored text - blue with shadow\n" , 0 ) |
107text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 108 109textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) 110textFrame.setSize( Size(15000,400)) 111textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) 112 113 114text.insertTextContent( cursor, textFrame, 0 ) 115 116textInTextFrame = textFrame.getText() 117cursorInTextFrame = textInTextFrame.createTextCursor() 118textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) | 107text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 108 109textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) 110textFrame.setSize( Size(15000,400)) 111textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) 112 113 114text.insertTextContent( cursor, textFrame, 0 ) 115 116textInTextFrame = textFrame.getText() 117cursorInTextFrame = textInTextFrame.createTextCursor() 118textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) |
119textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0) | 119textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the frame raises.",0) |
120text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 121 122cursor.setPropertyValue( "CharColor", 65536 ) 123cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) 124 | 120text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 121 122cursor.setPropertyValue( "CharColor", 65536 ) 123cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) 124 |
125text.insertString( cursor, " That's all for now !!" , 0 ) | 125text.insertString( cursor, " That's all for now!" , 0 ) |
126 | 126 |