#include #include ;*********************************************************************** ;* ;* The Contents of this file are made available subject to the terms of ;* the BSD license. ;* ;* Copyright 2000, 2010 Oracle and/or its affiliates. ;* All rights reserved. ;* ;* Redistribution and use in source and binary forms, with or without ;* modification, are permitted provided that the following conditions ;* are met: ;* 1. Redistributions of source code must retain the above copyright ;* notice, this list of conditions and the following disclaimer. ;* 2. Redistributions in binary form must reproduce the above copyright ;* notice, this list of conditions and the following disclaimer in the ;* documentation and/or other materials provided with the distribution. ;* 3. Neither the name of Sun Microsystems, Inc. nor the names of its ;* contributors may be used to endorse or promote products derived ;* from this software without specific prior written permission. ;* ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ;* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ;* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ;* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ;* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ;* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR ;* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE ;* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;* ;************************************************************************* ;The service manager is always the starting point ;If there is no office running then an office is started up Global $oServiceManager = ObjCreate("com.sun.star.ServiceManager") If @error Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONERROR, '$oServiceManager', '@error = ' & @error & @CRLF & '@extended = ' & @extended) ;Create the CoreReflection service that is later used to create structs Global $oCoreReflection = $oServiceManager.createInstance("com.sun.star.reflection.CoreReflection") ;Create the Desktop Global $oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop") ;Open a new empty writer document Global $args[1] Global $oDocument = $oDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, $args) ;Create a text object Global $oText = $oDocument.getText ;Create a cursor object Global $oCursor = $oText.createTextCursor ;Inserting some Text $oText.insertString($oCursor, "The first line in the newly created text document." & @LF, False) ;Inserting a second line $oText.insertString($oCursor, "Now we're in the second line", False) ;Create instance of a text table with 4 columns and 4 rows Global $oTable = $oDocument.createInstance("com.sun.star.text.TextTable") $oTable.initialize(4, 4) ;Insert the table $oText.insertTextContent($oCursor, $oTable, False) ;Get first row Global $oRows = $oTable.getRows Global $oRow = $oRows.getByIndex(0) ;Set the table background color $oTable.setPropertyValue("BackTransparent", False) $oTable.setPropertyValue("BackColor", 13421823) ;Set a different background color for the first row $oRow.setPropertyValue("BackTransparent", False) $oRow.setPropertyValue("BackColor", 6710932) ;Fill the first table row insertIntoCell("A1", "FirstColumn", $oTable) insertIntoCell("B1", "SecondColumn", $oTable) insertIntoCell("C1", "ThirdColumn", $oTable) insertIntoCell("D1", "SUM", $oTable) $oTable.getCellByName("A2").setValue(22.5) $oTable.getCellByName("B2").setValue(5615.3) $oTable.getCellByName("C2").setValue(-2315.7) $oTable.getCellByName("D2").setFormula("sum ") $oTable.getCellByName("A3").setValue(21.5) $oTable.getCellByName("B3").setValue(615.3) $oTable.getCellByName("C3").setValue(-315.7) $oTable.getCellByName("D3").setFormula("sum ") $oTable.getCellByName("A4").setValue(121.5) $oTable.getCellByName("B4").setValue(- 615.3) $oTable.getCellByName("C4").setValue(415.7) $oTable.getCellByName("D4").setFormula("sum ") ;Change the CharColor and add a Shadow $oCursor.setPropertyValue("CharColor", 255) $oCursor.setPropertyValue("CharShadowed", True) ;Create a paragraph break ;The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant $oText.insertControlCharacter($oCursor, 0, False) ;Inserting colored Text. $oText.insertString($oCursor, " This is a colored Text - blue with shadow" & @LF, False) ;Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK). $oText.insertControlCharacter($oCursor, 0, False) ;Create a TextFrame. Global $oTextFrame = $oDocument.createInstance("com.sun.star.text.TextFrame") ;Create a Size struct. Global $oSize = createStruct("com.sun.star.awt.Size") $oSize.Width = 15000 $oSize.Height = 400 $oTextFrame.setSize($oSize) ; TextContentAnchorType.AS_CHARACTER = 1 $oTextFrame.setPropertyValue("AnchorType", 1) ;insert the frame $oText.insertTextContent($oCursor, $oTextFrame, False) ;Get the text object of the frame Global $oFrameText = $oTextFrame.getText ;Create a cursor object Global $oFrameTextCursor = $oFrameText.createTextCursor ;Inserting some Text $oFrameText.insertString($oFrameTextCursor, "The first line in the newly created text frame.", _ False) $oFrameText.insertString($oFrameTextCursor, _ @LF & "With this second line the height of the frame raises.", False) ;Create a paragraph break ;The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant $oFrameText.insertControlCharacter($oCursor, 0, False) ;Change the CharColor and add a Shadow $oCursor.setPropertyValue("CharColor", 65536) $oCursor.setPropertyValue("CharShadowed", False) ;Insert another string $oText.insertString($oCursor, " That's all for now !!", False) If @error Then MsgBox(0, "", "An error occurred") EndIf Func insertIntoCell($sCellName, $sText, $oTable) Local $oCellText = $oTable.getCellByName($sCellName) Local $oCellCursor = $oCellText.createTextCursor $oCellCursor.setPropertyValue("CharColor", 16777215) $oCellText.insertString($oCellCursor, $sText, False) EndFunc ;==>insertIntoCell Func createStruct($sTypeName) Local $classSize = $oCoreReflection.forName($sTypeName) Local $aStruct $classSize.createObject($aStruct) Return $aStruct EndFunc ;==>createStruct