1import uno
2
3# a UNO struct later needed to create a document
4from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
5from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
6from com.sun.star.awt import Size
7
8from com.sun.star.lang import XMain
9
10def insertTextIntoCell( table, cellName, text, color ):
11    tableText = table.getCellByName( cellName )
12    cursor = tableText.createTextCursor()
13    cursor.setPropertyValue( "CharColor", color )
14    tableText.setString( text )
15
16
17def 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)
22
23    # open a writer document
24    doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
25
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 )
30
31    # create a text table
32    table = doc.createInstance( "com.sun.star.text.TextTable" )
33
34    # with 4 rows and 4 columns
35    table.initialize( 4,4)
36
37    text.insertTextContent( cursor, table, 0 )
38    rows = table.Rows
39
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 )
45
46    textColor = 16777215
47
48    insertTextIntoCell( table, "A1", "FirstColumn", textColor )
49    insertTextIntoCell( table, "B1", "SecondColumn", textColor )
50    insertTextIntoCell( table, "C1", "ThirdColumn", textColor )
51    insertTextIntoCell( table, "D1", "SUM", textColor )
52
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>")
60
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>")
65
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>")
70
71
72    cursor.setPropertyValue( "CharColor", 255 )
73    cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
74
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 )
78
79    textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
80    textFrame.setSize( Size(15000,400))
81    textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER )
82
83    text.insertTextContent( cursor, textFrame, 0 )
84
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 )
90
91    cursor.setPropertyValue( "CharColor", 65536 )
92    cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
93
94    text.insertString( cursor, " That's all for now !!" , 0 )
95
96g_exportedScripts = createTable,
97