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