swritercomp.py (bd8ef897) | swritercomp.py (d912c6c5) |
---|---|
1# ************************************************************* 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 --- 28 unchanged lines hidden (view full) --- 37 cursor = tableText.createTextCursor() 38 cursor.setPropertyValue( "CharColor", color ) 39 tableText.setString( text ) 40 41# the UNO component 42# implementing the interface com.sun.star.lang.XMain 43# unohelper.Base implements the XTypeProvider interface 44class SWriterComp(XMain,unohelper.Base): | 1# ************************************************************* 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 --- 28 unchanged lines hidden (view full) --- 37 cursor = tableText.createTextCursor() 38 cursor.setPropertyValue( "CharColor", color ) 39 tableText.setString( text ) 40 41# the UNO component 42# implementing the interface com.sun.star.lang.XMain 43# unohelper.Base implements the XTypeProvider interface 44class SWriterComp(XMain,unohelper.Base): |
45 def __init__( self, ctx ): 46 self.ctx = ctx | 45 def __init__( self, ctx ): 46 self.ctx = ctx |
47 | 47 |
48 # implementation for XMain.run( [in] sequence< any > ) 49 def run( self,args ): | 48 # implementation for XMain.run( [in] sequence< any > ) 49 def run( self,args ): |
50 | 50 |
51 ctx = self.ctx 52 smgr = ctx.ServiceManager 53 desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) | 51 ctx = self.ctx 52 smgr = ctx.ServiceManager 53 desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) |
54 | 54 |
55 # open a writer document 56 doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) | 55 # open a writer document 56 doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) |
57 | 57 |
58 text = doc.Text 59 cursor = text.createTextCursor() 60 text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) 61 text.insertString( cursor, "Now we are in the second line\n" , 0 ) | 58 text = doc.Text 59 cursor = text.createTextCursor() 60 text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) 61 text.insertString( cursor, "Now we are in the second line\n" , 0 ) |
62 | 62 |
63 # create a text table 64 table = doc.createInstance( "com.sun.star.text.TextTable" ) | 63 # create a text table 64 table = doc.createInstance( "com.sun.star.text.TextTable" ) |
65 | 65 |
66 # with 4 rows and 4 columns 67 table.initialize( 4,4) | 66 # with 4 rows and 4 columns 67 table.initialize( 4,4) |
68 | 68 |
69 text.insertTextContent( cursor, table, 0 ) 70 rows = table.Rows | 69 text.insertTextContent( cursor, table, 0 ) 70 rows = table.Rows |
71 | 71 |
72 table.setPropertyValue( "BackTransparent", uno.Bool(0) ) 73 table.setPropertyValue( "BackColor", 13421823 ) 74 row = rows.getByIndex(0) 75 row.setPropertyValue( "BackTransparent", uno.Bool(0) ) 76 row.setPropertyValue( "BackColor", 6710932 ) | 72 table.setPropertyValue( "BackTransparent", uno.Bool(0) ) 73 table.setPropertyValue( "BackColor", 13421823 ) 74 row = rows.getByIndex(0) 75 row.setPropertyValue( "BackTransparent", uno.Bool(0) ) 76 row.setPropertyValue( "BackColor", 6710932 ) |
77 | 77 |
78 textColor = 16777215 | 78 textColor = 16777215 |
79 | 79 |
80 insertTextIntoCell( table, "A1", "FirstColumn", textColor ) 81 insertTextIntoCell( table, "B1", "SecondColumn", textColor ) 82 insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) 83 insertTextIntoCell( table, "D1", "SUM", textColor ) | 80 insertTextIntoCell( table, "A1", "FirstColumn", textColor ) 81 insertTextIntoCell( table, "B1", "SecondColumn", textColor ) 82 insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) 83 insertTextIntoCell( table, "D1", "SUM", textColor ) |
84 | 84 |
85 values = ( (22.5,21.5,121.5), 86 (5615.3,615.3,-615.3), 87 (-2315.7,315.7,415.7) ) 88 table.getCellByName("A2").setValue(22.5) 89 table.getCellByName("B2").setValue(5615.3) 90 table.getCellByName("C2").setValue(-2315.7) 91 table.getCellByName("D2").setFormula("sum <A2:C2>") | 85 values = ( (22.5,21.5,121.5), 86 (5615.3,615.3,-615.3), 87 (-2315.7,315.7,415.7) ) 88 table.getCellByName("A2").setValue(22.5) 89 table.getCellByName("B2").setValue(5615.3) 90 table.getCellByName("C2").setValue(-2315.7) 91 table.getCellByName("D2").setFormula("sum <A2:C2>") |
92 | 92 |
93 table.getCellByName("A3").setValue(21.5) 94 table.getCellByName("B3").setValue(615.3) 95 table.getCellByName("C3").setValue(-315.7) 96 table.getCellByName("D3").setFormula("sum <A3:C3>") | 93 table.getCellByName("A3").setValue(21.5) 94 table.getCellByName("B3").setValue(615.3) 95 table.getCellByName("C3").setValue(-315.7) 96 table.getCellByName("D3").setFormula("sum <A3:C3>") |
97 | 97 |
98 table.getCellByName("A4").setValue(121.5) 99 table.getCellByName("B4").setValue(-615.3) 100 table.getCellByName("C4").setValue(415.7) 101 table.getCellByName("D4").setFormula("sum <A4:C4>") | 98 table.getCellByName("A4").setValue(121.5) 99 table.getCellByName("B4").setValue(-615.3) 100 table.getCellByName("C4").setValue(415.7) 101 table.getCellByName("D4").setFormula("sum <A4:C4>") |
102 103 | 102 103 |
104 cursor.setPropertyValue( "CharColor", 255 ) 105 cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) | 104 cursor.setPropertyValue( "CharColor", 255 ) 105 cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) |
106 | 106 |
107 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 108 text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 ) 109 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) | 107 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) 108 text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 ) 109 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) |
110 | 110 |
111 textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) 112 textFrame.setSize( Size(15000,400)) 113 textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) | 111 textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) 112 textFrame.setSize( Size(15000,400)) 113 textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) |
114 | 114 |
115 text.insertTextContent( cursor, textFrame, 0 ) | 115 text.insertTextContent( cursor, textFrame, 0 ) |
116 | 116 |
117 textInTextFrame = textFrame.getText() 118 cursorInTextFrame = textInTextFrame.createTextCursor() 119 textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) 120 textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0) 121 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) | 117 textInTextFrame = textFrame.getText() 118 cursorInTextFrame = textInTextFrame.createTextCursor() 119 textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) 120 textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0) 121 text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) |
122 | 122 |
123 cursor.setPropertyValue( "CharColor", 65536 ) 124 cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) | 123 cursor.setPropertyValue( "CharColor", 65536 ) 124 cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) |
125 | 125 |
126 text.insertString( cursor, " That's all for now !!" , 0 ) 127 return 0 | 126 text.insertString( cursor, " That's all for now !!" , 0 ) 127 return 0 |
128 129 130# pythonloader looks for a static g_ImplementationHelper variable 131g_ImplementationHelper = unohelper.ImplementationHelper() 132g_ImplementationHelper.addImplementation( \ | 128 129 130# pythonloader looks for a static g_ImplementationHelper variable 131g_ImplementationHelper = unohelper.ImplementationHelper() 132g_ImplementationHelper.addImplementation( \ |
133 SWriterComp,"org.openoffice.comp.pyuno.swriter",("org.openoffice.demo.SWriter",),) | 133 SWriterComp,"org.openoffice.comp.pyuno.swriter",("org.openoffice.demo.SWriter",),) |