1*cdf0e10cSrcweir'*********************************************************************** 2*cdf0e10cSrcweir'* 3*cdf0e10cSrcweir'* The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir'* the BSD license. 5*cdf0e10cSrcweir'* 6*cdf0e10cSrcweir'* Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir'* All rights reserved. 8*cdf0e10cSrcweir'* 9*cdf0e10cSrcweir'* Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir'* modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir'* are met: 12*cdf0e10cSrcweir'* 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir'* notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir'* 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir'* notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir'* documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir'* 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir'* contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir'* from this software without specific prior written permission. 20*cdf0e10cSrcweir'* 21*cdf0e10cSrcweir'* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir'* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir'* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir'* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir'* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir'* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir'* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir'* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir'* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir'* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir'* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir'* 33*cdf0e10cSrcweir'************************************************************************* 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir'The service manager is always the starting point 36*cdf0e10cSrcweir'If there is no office running then an office is started up 37*cdf0e10cSrcweirSet objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager") 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir'Create the CoreReflection service that is later used to create structs 40*cdf0e10cSrcweirSet objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection") 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir'Create the Desktop 43*cdf0e10cSrcweirSet objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop") 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir'Open a new empty writer document 46*cdf0e10cSrcweirDim args() 47*cdf0e10cSrcweirSet objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args) 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir'Create a text object 50*cdf0e10cSrcweirSet objText= objDocument.getText 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir'Create a cursor object 53*cdf0e10cSrcweirSet objCursor= objText.createTextCursor 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir'Inserting some Text 56*cdf0e10cSrcweirobjText.insertString objCursor, "The first line in the newly created text document." & vbLf, false 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir'Inserting a second line 59*cdf0e10cSrcweirobjText.insertString objCursor, "Now we're in the second line", false 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir'Create instance of a text table with 4 columns and 4 rows 62*cdf0e10cSrcweirSet objTable= objDocument.createInstance( "com.sun.star.text.TextTable") 63*cdf0e10cSrcweirobjTable.initialize 4, 4 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir'Insert the table 66*cdf0e10cSrcweirobjText.insertTextContent objCursor, objTable, false 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir'Get first row 69*cdf0e10cSrcweirSet objRows= objTable.getRows 70*cdf0e10cSrcweirSet objRow= objRows.getByIndex( 0) 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir'Set the table background color 73*cdf0e10cSrcweirobjTable.setPropertyValue "BackTransparent", false 74*cdf0e10cSrcweirobjTable.setPropertyValue "BackColor", 13421823 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir'Set a different background color for the first row 77*cdf0e10cSrcweirobjRow.setPropertyValue "BackTransparent", false 78*cdf0e10cSrcweirobjRow.setPropertyValue "BackColor", 6710932 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir'Fill the first table row 81*cdf0e10cSrcweirinsertIntoCell "A1","FirstColumn", objTable 82*cdf0e10cSrcweirinsertIntoCell "B1","SecondColumn", objTable 83*cdf0e10cSrcweirinsertIntoCell "C1","ThirdColumn", objTable 84*cdf0e10cSrcweirinsertIntoCell "D1","SUM", objTable 85*cdf0e10cSrcweir 86*cdf0e10cSrcweirobjTable.getCellByName("A2").setValue 22.5 87*cdf0e10cSrcweirobjTable.getCellByName("B2").setValue 5615.3 88*cdf0e10cSrcweirobjTable.getCellByName("C2").setValue -2315.7 89*cdf0e10cSrcweirobjTable.getCellByName("D2").setFormula"sum <A2:C2>" 90*cdf0e10cSrcweir 91*cdf0e10cSrcweirobjTable.getCellByName("A3").setValue 21.5 92*cdf0e10cSrcweirobjTable.getCellByName("B3").setValue 615.3 93*cdf0e10cSrcweirobjTable.getCellByName("C3").setValue -315.7 94*cdf0e10cSrcweirobjTable.getCellByName("D3").setFormula "sum <A3:C3>" 95*cdf0e10cSrcweir 96*cdf0e10cSrcweirobjTable.getCellByName("A4").setValue 121.5 97*cdf0e10cSrcweirobjTable.getCellByName("B4").setValue -615.3 98*cdf0e10cSrcweirobjTable.getCellByName("C4").setValue 415.7 99*cdf0e10cSrcweirobjTable.getCellByName("D4").setFormula "sum <A4:C4>" 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir'Change the CharColor and add a Shadow 102*cdf0e10cSrcweirobjCursor.setPropertyValue "CharColor", 255 103*cdf0e10cSrcweirobjCursor.setPropertyValue "CharShadowed", true 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir'Create a paragraph break 106*cdf0e10cSrcweir'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant 107*cdf0e10cSrcweirobjText.insertControlCharacter objCursor, 0 , false 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir'Inserting colored Text. 110*cdf0e10cSrcweirobjText.insertString objCursor, " This is a colored Text - blue with shadow" & vbLf, false 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK). 113*cdf0e10cSrcweirobjText.insertControlCharacter objCursor, 0, false 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir'Create a TextFrame. 116*cdf0e10cSrcweirSet objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame") 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir'Create a Size struct. 119*cdf0e10cSrcweirSet objSize= createStruct("com.sun.star.awt.Size") 120*cdf0e10cSrcweirobjSize.Width= 15000 121*cdf0e10cSrcweirobjSize.Height= 400 122*cdf0e10cSrcweirobjTextFrame.setSize( objSize) 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir' TextContentAnchorType.AS_CHARACTER = 1 125*cdf0e10cSrcweirobjTextFrame.setPropertyValue "AnchorType", 1 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir'insert the frame 128*cdf0e10cSrcweirobjText.insertTextContent objCursor, objTextFrame, false 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir'Get the text object of the frame 131*cdf0e10cSrcweirSet objFrameText= objTextFrame.getText 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir'Create a cursor object 135*cdf0e10cSrcweirSet objFrameTextCursor= objFrameText.createTextCursor 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir'Inserting some Text 138*cdf0e10cSrcweirobjFrameText.insertString objFrameTextCursor, "The first line in the newly created text frame.", _ 139*cdf0e10cSrcweir false 140*cdf0e10cSrcweirobjFrameText.insertString objFrameTextCursor, _ 141*cdf0e10cSrcweir vbLf & "With this second line the height of the frame raises.", false 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir'Create a paragraph break 144*cdf0e10cSrcweir'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant 145*cdf0e10cSrcweirobjFrameText.insertControlCharacter objCursor, 0 , false 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir'Change the CharColor and add a Shadow 148*cdf0e10cSrcweirobjCursor.setPropertyValue "CharColor", 65536 149*cdf0e10cSrcweirobjCursor.setPropertyValue "CharShadowed", false 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir'Insert another string 152*cdf0e10cSrcweirobjText.insertString objCursor, " That's all for now !!", false 153*cdf0e10cSrcweir 154*cdf0e10cSrcweirOn Error Resume Next 155*cdf0e10cSrcweirIf Err Then 156*cdf0e10cSrcweir MsgBox "An error occurred" 157*cdf0e10cSrcweirEnd If 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweirSub insertIntoCell( strCellName, strText, objTable) 161*cdf0e10cSrcweir Set objCellText= objTable.getCellByName( strCellName) 162*cdf0e10cSrcweir Set objCellCursor= objCellText.createTextCursor 163*cdf0e10cSrcweir objCellCursor.setPropertyValue "CharColor",16777215 164*cdf0e10cSrcweir objCellText.insertString objCellCursor, strText, false 165*cdf0e10cSrcweirEnd Sub 166*cdf0e10cSrcweir 167*cdf0e10cSrcweirFunction createStruct( strTypeName) 168*cdf0e10cSrcweir Set classSize= objCoreReflection.forName( strTypeName) 169*cdf0e10cSrcweir Dim aStruct 170*cdf0e10cSrcweir classSize.createObject aStruct 171*cdf0e10cSrcweir Set createStruct= aStruct 172*cdf0e10cSrcweirEnd Function 173