:Start of OOoAutomation
![]() | ![]() |
|---|
If you are viewing this script in your browser you can save it as a VDS 5.x source file (*.dsc) to run it.
#
# DragonSphere Software's Home Page
#
# All Source Files for this demo
Title OpenOffice.org Example
################################################ DESCRIPTION #################################################
# #
# This is a very simple example for automating the OpenOffice.org Writer application #
# OpenOffice.org is a opensource Office Suite maintained and developed by the JAVA community #
##############################################################################################################
# Below is the VBScript we will attempt to translate into GadgetX syntax
# Dim objServiceManager As Object
# Dim objDesktop As Object
# Dim args()
# Set objServiceManager= CreateObject("com.sun.star.ServiceManager")
# Set Stardesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
# Set doc = Stardesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
# Set text = doc.getText()
# text.setString("Hello World")
# REM You can get the full example in the SDK (under OLE examples)
# REM Read the Automation Bridge part of the Developer's Guide for writing code with WSH or JScript,
# both are very similiar to VBScript
# Below is the GadgetX version of the VBScript above.
If @Greater(@Name(@SYSINFO(DSVER)),4)
External GadgetX.dll,@SYSINFO(DSVER)
# GadgetX command and functions
#DEFINE COMMAND,GADGETX,DEFINE,SET,OLE
#DEFINE FUNCTION,GADGETX,GET,OLE,SIZEOF,ADDROF
End
# Initialize OLE
Ole Init
# Define the objects and variables needed
Define Variable,Object,objServiceManager
Define Variable,Object,Stardesktop
Define Variable,Object,doc
Define Variable,Object,text
# This is a Variant of type SafeArray
Define Variable,Variant,args,^a
# Set the SafeArray Variant to NULL
Set args,NULL,^a
# Create the OpenOffice.org ServiceManager Object
Set objServiceManager,@Ole(Create,com.sun.star.ServiceManager,NULL)
# Create an instance of the Service Manager Desktop Object
Set Stardesktop,@Ole(Call,objServiceManager,^o,"createInstance(^B)","com.sun.star.frame.Desktop")
# Get the document object from the desktop
Set doc,@Ole(Call,Stardesktop,^o,"loadComponentFromURL(^B,^B,^d,^a)","private:factory/swriter", "_blank", 0, args)
# Get the Text object from the document
Set text,@Ole(Get,doc,^o,"getText()")
# Place some text on the Text object
Ole Call,text,"setString(^B)","GadgetX Rocks OpenOffice.org!!!"
# That's it we are done
Info Click Ok to close this OpenOffice Text Document example.
:CLOSE
# Cleanup and close out everything
Ole Call,doc,"Close(^B)",false
Ole Call,Stardesktop,"terminate()"
Ole Free,Object,text
Ole Free,Object,doc
Ole Free,Object,Stardesktop
Ole Free,Object,objServiceManager
# Uninitialize OLE
Ole UnInit
Exit
copyright © DragonSphere Software 2000-2006
Terms and Conditions