merge the formfield patch from ooo-build
[ooovba.git] / scripting / examples / python / pythonSamples / TableSample.py
blob793b79725a74780cb31d7763d73455e1e0da83f7
1 import uno
3 # a UNO struct later needed to create a document
4 from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
5 from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
6 from com.sun.star.awt import Size
8 from com.sun.star.lang import XMain
10 def insertTextIntoCell( table, cellName, text, color ):
11 tableText = table.getCellByName( cellName )
12 cursor = tableText.createTextCursor()
13 cursor.setPropertyValue( "CharColor", color )
14 tableText.setString( text )
17 def createTable():
18 """creates a new writer document and inserts a table with some data (also known as the SWriter sample)"""
19 ctx = uno.getComponentContext()
20 smgr = ctx.ServiceManager
21 desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
23 # open a writer document
24 doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
26 text = doc.Text
27 cursor = text.createTextCursor()
28 text.insertString( cursor, "The first line in the newly created text document.\n", 0 )
29 text.insertString( cursor, "Now we are in the second line\n" , 0 )
31 # create a text table
32 table = doc.createInstance( "com.sun.star.text.TextTable" )
34 # with 4 rows and 4 columns
35 table.initialize( 4,4)
37 text.insertTextContent( cursor, table, 0 )
38 rows = table.Rows
40 table.setPropertyValue( "BackTransparent", uno.Bool(0) )
41 table.setPropertyValue( "BackColor", 13421823 )
42 row = rows.getByIndex(0)
43 row.setPropertyValue( "BackTransparent", uno.Bool(0) )
44 row.setPropertyValue( "BackColor", 6710932 )
46 textColor = 16777215
48 insertTextIntoCell( table, "A1", "FirstColumn", textColor )
49 insertTextIntoCell( table, "B1", "SecondColumn", textColor )
50 insertTextIntoCell( table, "C1", "ThirdColumn", textColor )
51 insertTextIntoCell( table, "D1", "SUM", textColor )
53 values = ( (22.5,21.5,121.5),
54 (5615.3,615.3,-615.3),
55 (-2315.7,315.7,415.7) )
56 table.getCellByName("A2").setValue(22.5)
57 table.getCellByName("B2").setValue(5615.3)
58 table.getCellByName("C2").setValue(-2315.7)
59 table.getCellByName("D2").setFormula("sum <A2:C2>")
61 table.getCellByName("A3").setValue(21.5)
62 table.getCellByName("B3").setValue(615.3)
63 table.getCellByName("C3").setValue(-315.7)
64 table.getCellByName("D3").setFormula("sum <A3:C3>")
66 table.getCellByName("A4").setValue(121.5)
67 table.getCellByName("B4").setValue(-615.3)
68 table.getCellByName("C4").setValue(415.7)
69 table.getCellByName("D4").setFormula("sum <A4:C4>")
72 cursor.setPropertyValue( "CharColor", 255 )
73 cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
75 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
76 text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 )
77 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
79 textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
80 textFrame.setSize( Size(15000,400))
81 textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER )
83 text.insertTextContent( cursor, textFrame, 0 )
85 textInTextFrame = textFrame.getText()
86 cursorInTextFrame = textInTextFrame.createTextCursor()
87 textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 )
88 textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0)
89 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
91 cursor.setPropertyValue( "CharColor", 65536 )
92 cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
94 text.insertString( cursor, " That's all for now !!" , 0 )
96 g_exportedScripts = createTable,