19f22d7c2SAndrew Rist# ************************************************************* 2*d47d317bSmseidel# 39f22d7c2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 49f22d7c2SAndrew Rist# or more contributor license agreements. See the NOTICE file 59f22d7c2SAndrew Rist# distributed with this work for additional information 69f22d7c2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 79f22d7c2SAndrew Rist# to you under the Apache License, Version 2.0 (the 89f22d7c2SAndrew Rist# "License"); you may not use this file except in compliance 99f22d7c2SAndrew Rist# with the License. You may obtain a copy of the License at 10*d47d317bSmseidel# 119f22d7c2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*d47d317bSmseidel# 139f22d7c2SAndrew Rist# Unless required by applicable law or agreed to in writing, 149f22d7c2SAndrew Rist# software distributed under the License is distributed on an 159f22d7c2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f22d7c2SAndrew Rist# KIND, either express or implied. See the License for the 179f22d7c2SAndrew Rist# specific language governing permissions and limitations 189f22d7c2SAndrew Rist# under the License. 19*d47d317bSmseidel# 209f22d7c2SAndrew Rist# ************************************************************* 219f22d7c2SAndrew Rist 22cdf0e10cSrcweirimport uno 23cdf0e10cSrcweir 24cdf0e10cSrcweir# a UNO struct later needed to create a document 25cdf0e10cSrcweirfrom com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK 26cdf0e10cSrcweirfrom com.sun.star.text.TextContentAnchorType import AS_CHARACTER 27cdf0e10cSrcweirfrom com.sun.star.awt import Size 28cdf0e10cSrcweir 29cdf0e10cSrcweirfrom com.sun.star.lang import XMain 30cdf0e10cSrcweir 31cdf0e10cSrcweirdef insertTextIntoCell( table, cellName, text, color ): 32cdf0e10cSrcweir tableText = table.getCellByName( cellName ) 33cdf0e10cSrcweir cursor = tableText.createTextCursor() 34cdf0e10cSrcweir cursor.setPropertyValue( "CharColor", color ) 35cdf0e10cSrcweir tableText.setString( text ) 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweirdef createTable(): 3928e51104SPedro Giffuni """creates a new writer document and inserts a table with some data (also known as the SWriter sample)""" 40cdf0e10cSrcweir ctx = uno.getComponentContext() 41cdf0e10cSrcweir smgr = ctx.ServiceManager 42cdf0e10cSrcweir desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) 4328e51104SPedro Giffuni 44cdf0e10cSrcweir # open a writer document 45cdf0e10cSrcweir doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) 4628e51104SPedro Giffuni 47cdf0e10cSrcweir text = doc.Text 48cdf0e10cSrcweir cursor = text.createTextCursor() 49cdf0e10cSrcweir text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) 50*d47d317bSmseidel text.insertString( cursor, "Now we are in the second line.\n" , 0 ) 5128e51104SPedro Giffuni 52cdf0e10cSrcweir # create a text table 53cdf0e10cSrcweir table = doc.createInstance( "com.sun.star.text.TextTable" ) 54cdf0e10cSrcweir 55cdf0e10cSrcweir # with 4 rows and 4 columns 56cdf0e10cSrcweir table.initialize( 4,4) 57cdf0e10cSrcweir 58cdf0e10cSrcweir text.insertTextContent( cursor, table, 0 ) 59cdf0e10cSrcweir rows = table.Rows 60cdf0e10cSrcweir 61cdf0e10cSrcweir table.setPropertyValue( "BackTransparent", uno.Bool(0) ) 62cdf0e10cSrcweir table.setPropertyValue( "BackColor", 13421823 ) 63cdf0e10cSrcweir row = rows.getByIndex(0) 64cdf0e10cSrcweir row.setPropertyValue( "BackTransparent", uno.Bool(0) ) 65cdf0e10cSrcweir row.setPropertyValue( "BackColor", 6710932 ) 66cdf0e10cSrcweir 67cdf0e10cSrcweir textColor = 16777215 68cdf0e10cSrcweir 69cdf0e10cSrcweir insertTextIntoCell( table, "A1", "FirstColumn", textColor ) 70cdf0e10cSrcweir insertTextIntoCell( table, "B1", "SecondColumn", textColor ) 71cdf0e10cSrcweir insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) 72cdf0e10cSrcweir insertTextIntoCell( table, "D1", "SUM", textColor ) 73cdf0e10cSrcweir 74cdf0e10cSrcweir values = ( (22.5,21.5,121.5), 75cdf0e10cSrcweir (5615.3,615.3,-615.3), 76cdf0e10cSrcweir (-2315.7,315.7,415.7) ) 77cdf0e10cSrcweir table.getCellByName("A2").setValue(22.5) 78cdf0e10cSrcweir table.getCellByName("B2").setValue(5615.3) 79cdf0e10cSrcweir table.getCellByName("C2").setValue(-2315.7) 80cdf0e10cSrcweir table.getCellByName("D2").setFormula("sum <A2:C2>") 81cdf0e10cSrcweir 82cdf0e10cSrcweir table.getCellByName("A3").setValue(21.5) 83cdf0e10cSrcweir table.getCellByName("B3").setValue(615.3) 84cdf0e10cSrcweir table.getCellByName("C3").setValue(-315.7) 85cdf0e10cSrcweir table.getCellByName("D3").setFormula("sum <A3:C3>") 86cdf0e10cSrcweir 87cdf0e10cSrcweir table.getCellByName("A4").setValue(121.5) 88cdf0e10cSrcweir table.getCellByName("B4").setValue(-615.3) 89cdf0e10cSrcweir table.getCellByName("C4").setValue(415.7) 90cdf0e10cSrcweir table.getCellByName("D4").setFormula("sum <A4:C4>") 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir cursor.setPropertyValue( "CharColor", 255 ) 94cdf0e10cSrcweir cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) 95cdf0e10cSrcweir 96cdf0e10cSrcweir text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 97*d47d317bSmseidel text.insertString( cursor, " This is a colored text - blue with shadow\n" , 0 ) 98cdf0e10cSrcweir text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 99cdf0e10cSrcweir 100cdf0e10cSrcweir textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) 101cdf0e10cSrcweir textFrame.setSize( Size(15000,400)) 102cdf0e10cSrcweir textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) 103cdf0e10cSrcweir 104cdf0e10cSrcweir text.insertTextContent( cursor, textFrame, 0 ) 105cdf0e10cSrcweir 106cdf0e10cSrcweir textInTextFrame = textFrame.getText() 107cdf0e10cSrcweir cursorInTextFrame = textInTextFrame.createTextCursor() 108cdf0e10cSrcweir textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) 109*d47d317bSmseidel textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the frame raises.",0) 110cdf0e10cSrcweir text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 111cdf0e10cSrcweir 112cdf0e10cSrcweir cursor.setPropertyValue( "CharColor", 65536 ) 113cdf0e10cSrcweir cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) 114cdf0e10cSrcweir 115*d47d317bSmseidel text.insertString( cursor, " That's all for now!" , 0 ) 116cdf0e10cSrcweir 117cdf0e10cSrcweirg_exportedScripts = createTable, 118