Path
 
  
Children

pwScript

Drives an installed OpenOffice suite to implement the demo known as WriterDemo

This is a pwScripter script:

'***********************************************************************
'*
'*  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


newscript

dim vblf = chr(0x0a)

FUNCTION rgb ( red, green, blue )
  ' in pwScripter    rgb =    red  * 65536  + green * 256   + blue           ' same as VB and VBA
  ' LibreOffice      rgb =    red           + green * 256   + blue * 65536
  ' also LibreOffice requires that RGB is a 32 bit value
  returnValue =  c2ui32 ( red + green * 256 + blue * 65536 )
END FUNCTION

FUNCTION insertIntoCell( strCellName, strText, objTable)
    dim objCellText= objTable.getCellByName( strCellName)
    dim objCellCursor= objCellText.createTextCursor
    objCellCursor.setPropertyValue ("CharColor",16777215)
    objCellText.insertString( objCellCursor, strText, false)
End FUNCTION

dim objServiceManager=  CreateObject("com.sun.star.ServiceManager")

'Create the CoreReflection service that is later used to create structs
dim objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")

'Create the Desktop
dim objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")

'Open a new empty writer document
Dim args(100)
dim objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)

'Create a text object
Dim objText= objDocument.getText

'Create a cursor object
Dim objCursor= objText.createTextCursor

'Inserting some Text

objText.insertString (objCursor, "The first line in the newly created text document." & vbLf, false)
  
'Inserting a second line
objText.insertString( objCursor, "Now we're in the second line", false)

'Create instance of a text table with 4 columns and 4 rows
dim objTable= objDocument.createInstance( "com.sun.star.text.TextTable")
objTable.initialize( 4, 4)

'Insert the table
objText.insertTextContent (objCursor, objTable, false )

'Get first row
dim objRows= objTable.getRows
dim objRow= objRows.getByIndex( 0)

'Set the table background color
objTable.setPropertyValue ("BackTransparent", false)
objTable.setPropertyValue ("BackColor", rgb( 0xff, 0xcc, 0xcc) ) ' 13421823

'Set a different background color for the first row
objRow.setPropertyValue ("BackTransparent", false)
objRow.setPropertyValue ("BackColor",  rgb( 0x94, 0x66, 0x66)  ) ' 6710932

'Fill the first table row
insertIntoCell ("A1","FirstColumn", objTable )
insertIntoCell ("B1","SecondColumn", objTable)
insertIntoCell( "C1","ThirdColumn",objTable)
insertIntoCell ("D1","SUM",objTable )

objTable.getCellByName("A2").setValue (22.5)
objTable.getCellByName("B2").setValue (5615.3)
objTable.getCellByName("C2").setValue (-2315.7)
objTable.getCellByName("D2").setFormula ("sum ")
    
objTable.getCellByName("A3").setValue (21.5)
objTable.getCellByName("B3").setValue (615.3)
objTable.getCellByName("C3").setValue (-315.7)
objTable.getCellByName("D3").setFormula ("sum ")
          
objTable.getCellByName("A4").setValue (121.5)
objTable.getCellByName("B4").setValue (-615.3)
objTable.getCellByName("C4").setValue (415.7)
objTable.getCellByName("D4").setFormula ("sum ")
    
'Change the CharColor and add a Shadow
objCursor.setPropertyValue( "CharColor", rgb(255,0,0))
objCursor.setPropertyValue ("CharShadowed", true)

'Create a paragraph break
'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
objText.insertControlCharacter( objCursor, 0 , false)

'Inserting colored Text.
objText.insertString (objCursor, " This is a colored Text - blue with shadow" & vbLf, false)

'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
objText.insertControlCharacter (objCursor, 0, false )
      
'Create a TextFrame.
dim objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame")

'Create a Size struct.
dim objSize= objServiceManager.Bridge_GetStruct("com.sun.star.awt.Size")
  
objSize.Width= 15000
objSize.Height= 800
objTextFrame.setSize( objSize)

' TextContentAnchorType.AS_CHARACTER = 1
objTextFrame.setPropertyValue ("AnchorType", 1)

'insert the frame
objText.insertTextContent (objCursor, objTextFrame, false)

'Get the text object of the frame
dim objFrameText= objTextFrame.getText

'Create a cursor object
dim objFrameTextCursor= objFrameText.createTextCursor
    
'Inserting some Text
objFrameText.insertString( objFrameTextCursor, "The first line in the newly created text frame.", _
                          false    )
objFrameText.insertString (objFrameTextCursor, _
                          vbLf & "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
objFrameText.insertControlCharacter (objCursor, 0 , false)

'Change the CharColor and add a Shadow
objCursor.setPropertyValue ("CharColor", rgb(0x0,0x0,0x01) ) ' 65536
objCursor.setPropertyValue ("CharShadowed", false)

'Insert another string
objText.insertString (objCursor, " That's all for now !!", false )    




 
smallest  smaller  (columns)  larger  largest     Items 1 --- 1 of 1   min  less  (rows)  more  max  

 


 
Items 1 --- 1 of 1

 

      Disclaimer    Contact
Author: George Salisbury 2023-08-16 19:00
Help