Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Schdluded Task: How call (with OLE) "com.sun.star.ServiceManager"

121 views
Skip to first unread message

jogabar

unread,
Oct 26, 2007, 10:14:45 PM10/26/07
to
Hi:

I programmed with Harbour (clipper) to processing data make, using
calc, file .xls. This work very, very good and nice in any session,
but this program is necesary work like Scheduled task in my Windows
2000 Server.

Are only 2 or 3 programs and not necesary buy licenc of Microsoft
Office, if can make same with OpenOffice

Error when program is called by Scheduled Task is in:

oServiceManager := TOleAuto():New("com.sun.star.ServiceManager")

How can make work my program ?


Thanks

Jorge

...Sorry my ad english.

N:dlzc D:aol T:com (dlzc)

unread,
Oct 26, 2007, 10:34:30 PM10/26/07
to
Dear jogabar:

"jogabar" <jorge....@gmail.com> wrote in message
news:1193451285....@57g2000hsv.googlegroups.com...

Provided by Klas Engwall, December 2006 on the old news server:
<QUOTE>
Go to http://api.openoffice.org/ and look for the link to the
Developer's Guide almost at the top of the page. It is a 25 MB
pdf. There you can also find an SDK, a code snippet base and
various other
helpful things.
<END QUOTE>

Provided by Michael Baumann, December 2006 on the old news
server:
<QUOTE>
Gerald Drouillard posted very good sources and examples of how to
use
OO OLE with xHarbour. Thanks again to Gerald!

You will also find a lot of hints in
http://en.wikipedia.org/wiki/StarOffice_Basic

HTH
Michael
Vienna/Austria/Europe

--------------Geralds message from here on---------------
Date: Mon, 20 Feb 2006 22:49:56 -0500
From: Gerald Drouillard <ger...@drouillard.ca>
Newsgroups: xHarbour
Subject: Re: OLE & openoffice spreadsheet

Here is a little something to get you started....

#include "pushpop.ch"
#include "mycommon.ch"
#include "common.ch"

/**********************************************************************
************************************/

// Testing programs and sample programs below

function testexcel()

local lRtn := .t.

LOCAL oExcel

LOCAL oBook
LOCAL oSheet

IF !isnt()
okmsg({"...Spreadsheet Creation...",;
"This functionality is not available for Win98"})
return(.f.)
ENDIF

IF !isnt().and.islinkedin('createobject()')
//save win9x from excel slowdown...
OleInitialize()
ENDIF

// gjh remove - this statement was causing problems with xHarbour
oExcel := CREATEOBJECT( "Excel.Application" )

oBook := oExcel:WorkBooks:Add()

oSheet := oBook:Worksheets(1)
oSheet:Name := 'Michigan'

oSheet:Cells( 1, 1 ):Value = "Sheet 1 This is a test"

oSheet := oBook:Worksheets(2)

oSheet:Cells( 1, 1 ):Value = "Sheet 2 This is a test"

oExcel:Visible := .F.

oSheet:SaveAs( "C:\SWAP\ATEST.XLS" )

oExcel:Quit()

IF !isnt().and.islinkedin('createobject()')
//save win9x from excel slowdown...
OleUnInitialize()
ENDIF

/*
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add

'Add data to cells of the first worksheet in the new workbook
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"

'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
*/

return(lRtn)

function testoo()

local lRtn := .t.

local oDoc
local oSheet
local oFormats
local oLocale

LOCAL aOneArg := array(1)
LOCAL cFile, cURL

IF !isnt()
okmsg({"...Spreadsheet Creation...",;
"This functionality is not available for Win98"})
return(.f.)
ENDIF

IF !isnt().and.islinkedin('createobject()')
//save win9x from excel slowdown...
OleInitialize()
ENDIF

oDoc := OOoOpenURL( "private:factory/scalc" )

// Get first sheet
oSheet := oDoc:getSheets():getByIndex( 0 )
oSheet:Name := "Michigan"

*-----
* Put some sales figures onto the sheet.
oSheet:getCellByPosition( 0, 0 ):setString( "Month" )
oSheet:getCellByPosition( 1, 0 ):setString( "Sales" )
oSheet:getCellByPosition( 2, 0 ):setString( "End Date" )

// Get second sheet
oSheet := oDoc:getSheets():getByIndex( 1 )
oSheet:Name := "Indiana"

*-----
* Put some sales figures onto the sheet.
oSheet:getCellByPosition( 0, 0 ):setString( "Indiana Month" )
oSheet:getCellByPosition( 1, 0 ):setString( "Indiana Sales" )
oSheet:getCellByPosition( 2, 0 ):setString( "Indiana End
Date" )

/*
oSheet.getCellByPosition( 0, 1 ).setString( "Jan" )
oSheet.getCellByPosition( 0, 2 ).setString( "Feb" )
oSheet.getCellByPosition( 0, 3 ).setString( "Mar" )
oSheet.getCellByPosition( 0, 4 ).setString( "Apr" )
oSheet.getCellByPosition( 0, 5 ).setString( "May" )
oSheet.getCellByPosition( 0, 6 ).setString( "Jun" )
oSheet.getCellByPosition( 0, 7 ).setString( "Jul" )
oSheet.getCellByPosition( 0, 8 ).setString( "Aug" )
oSheet.getCellByPosition( 0, 9 ).setString( "Sep" )
oSheet.getCellByPosition( 0, 10 ).setString( "Oct" )
oSheet.getCellByPosition( 0, 11 ).setString( "Nov" )
oSheet.getCellByPosition( 0, 12 ).setString( "Dec" )

oSheet.getCellByPosition( 1, 1 ).setValue( 3826.37 )
oSheet.getCellByPosition( 1, 2 ).setValue( 3504.21 )
oSheet.getCellByPosition( 1, 3 ).setValue( 2961.45 )
oSheet.getCellByPosition( 1, 4 ).setValue( 2504.12 )
oSheet.getCellByPosition( 1, 5 ).setValue( 2713.98 )
oSheet.getCellByPosition( 1, 6 ).setValue( 2448.17 )
oSheet.getCellByPosition( 1, 7 ).setValue( 1802.13 )
oSheet.getCellByPosition( 1, 8 ).setValue( 2203.22 )
oSheet.getCellByPosition( 1, 9 ).setValue( 1502.54 )
oSheet.getCellByPosition( 1, 10 ).setValue( 1207.68 )
oSheet.getCellByPosition( 1, 11 ).setValue( 1819.71 )
oSheet.getCellByPosition( 1, 12 ).setValue( 986.03 )

oSheet.getCellByPosition( 2, 1 ).setFormula(
"=DATE(2004;01;31)" )
oSheet.getCellByPosition( 2, 2 ).setFormula(
"=DATE(2004;02;29)" )
oSheet.getCellByPosition( 2, 3 ).setFormula(
"=DATE(2004;03;31)" )
oSheet.getCellByPosition( 2, 4 ).setFormula(
"=DATE(2004;04;30)" )
oSheet.getCellByPosition( 2, 5 ).setFormula(
"=DATE(2004;05;31)" )
oSheet.getCellByPosition( 2, 6 ).setFormula(
"=DATE(2004;06;30)" )
oSheet.getCellByPosition( 2, 7 ).setFormula(
"=DATE(2004;07;31)" )
oSheet.getCellByPosition( 2, 8 ).setFormula(
"=DATE(2004;08;31)" )
oSheet.getCellByPosition( 2, 9 ).setFormula(
"=DATE(2004;09;30)" )
* Note that these last three dates are not set as DATE()
function
calls.
oSheet.getCellByPosition( 2, 10 ).setFormula( "10/31/2004" )
oSheet.getCellByPosition( 2, 11 ).setFormula( "11/30/2004" )
oSheet.getCellRangeByName( "C13" ).setFormula( "12/31/2004" )
*-----

*/

* Format the date cells as dates.
// oFormats := oDoc.getNumberFormats()
// oLocale := OOoCreateStruct( "com.sun.star.lang.Locale" )

// * com.sun.star.util.NumberFormat.DATE = 2
// nDateKey = oFormats.getStandardFormat( 2, oLocale )
// oCell = oSheet.getCellRangeByName( "C2:C13" )
// oCell.NumberFormat = nDateKey

* cFile = GetDesktopFolderPathname()+"example"

cFile = "c:\swap\test"

* Now save the spreadsheet.
cURL := OOoConvertToURL( cFile + ".sxw" )
aOneArg[1] := OOoMakePropertyValue( "Overwrite", .T. )
oDoc:storeToUrl( cURL, aOneArg )

* Now save it as Excel
cURL := OOoConvertToURL( cFile + ".xls" )
aOneArg[1] := OOoMakePropertyValue( "FilterName", "MS Excel
97" )
oDoc:storeToUrl( cURL, aOneArg )

* Close the document.

oDoc:close( 1 )

IF !isnt().and.islinkedin('createobject()')
//save win9x from excel slowdown...
OleUnInitialize()
ENDIF

return(lRtn)

* Open or Create a document from it's URL.
* New documents are created by URL's such as:
* private:factory/sdraw
* private:factory/swriter
* private:factory/scalc
* private:factory/simpress
FUNCTION OOoOpenURL( cURL )
* LOCAL oPropertyValue
* oPropertyValue = OOoCreateStruct(
"com.sun.star.beans.PropertyValue" )

* LOCAL ARRAY aNoArgs[1]
* aNoArgs[1] = oPropertyValue
* aNoArgs[1].Name = "ReadOnly"
* aNoArgs[1].Value = .F.

* These two lines replace the alternate version above,
* which are left commented for the insight they provide.
LOCAL aNoArgs := array(1)
LOCAL oDesktop
LOCAL oDoc

aNoArgs[1] := OOoMakePropertyValue( "Hidden", .F. )

oDesktop := OOoGetDesktop()

oDoc := oDesktop:LoadComponentFromUrl( cURL, "_blank", 0,
aNoargs )

* Make sure that arrays passed to this document are passed
zero
based.
// COMARRAY( oDoc, 10 )

RETURN(oDoc)

* Create a com.sun.star.beans.PropertyValue struct and return it.
FUNCTION OOoMakePropertyValue( cName, uValue, nHandle, nState )
LOCAL oPropertyValue
oPropertyValue := OOoCreateStruct(
"com.sun.star.beans.PropertyValue" )

oPropertyValue:Name := cName
oPropertyValue:Value := uValue

IF TYPE([nHandle])="N"
oPropertyValue:Handle := nHandle
ENDIF
IF TYPE([nState])="N"
oPropertyValue:State := nState
ENDIF

RETURN(oPropertyValue)

* Sugar coated routine to create any UNO struct.
* Use the Bridge_GetStruct() feature of the OLE-UNO bridge.
FUNCTION OOoCreateStruct( cTypeName )
LOCAL oServiceManager
lOCAL oStruct
LOCAL cOldErrHandler

oServiceManager := OOoGetServiceManager()

// cOldErrHandler := ON( "ERROR" )
// ON ERROR := DoNothing__ErrorHandler( ERROR(), MESSAGE(),
LINENO(),
SYS(16), PROGRAM(), SYS(2018) )

oStruct := oServiceManager:Bridge_GetStruct( cTypeName )

// ON ERROR &cOldErrHandler

// IF empty(oStruct)
// =__OOoReleaseCachedVars()
// oServiceManager := OOoGetServiceManager()
// oStruct := oServiceManager:Bridge_GetStruct( cTypeName )
// ENDIF

RETURN(oStruct)

* Return the OpenOffice.org desktop object.
* Cache it in a global variable.
* Create it if not already cached.
FUNCTION OOoGetDesktop()
PUBLIC goOOoDesktop

IF (VALTYPE(goOOoDesktop)!="O") .OR. empty(goOOoDesktop)
goOOoDesktop := OOoServiceManager_CreateInstance(
"com.sun.star.frame.Desktop" )
// COMARRAY( goOOoDesktop, 10 )
ENDIF
RETURN(goOOoDesktop)

* Return the OpenOffice.org service manager object.
* Cache it in a global variable.
* Create it if not already cached.
FUNCTION OOoGetServiceManager()
PUBLIC goOOoServiceManager

IF (VALTYPE(goOOoServiceManager)!="O") .OR. empty(
goOOoServiceManager )
// goOOoServiceManager := ' '
// gjh remove this statement was causing problems with
xHarbour
goOOoServiceManager := CREATEOBJECT(
"com.sun.star.ServiceManager" )
ENDIF
RETURN(goOOoServiceManager)

* Sugar coated routine to ask the service manager to
* create you an instance of some other OpenOffice.org UNO
object.
FUNCTION OOoServiceManager_CreateInstance( cServiceName )
LOCAL oServiceManager
LOCAL oInstance
LOCAL cOldErrHandler

oServiceManager = OOoGetServiceManager()

// cOldErrHandler = ON( "ERROR" )
// ON ERROR = DoNothing__ErrorHandler( ERROR(), MESSAGE(),
LINENO(),
SYS(16), PROGRAM(), SYS(2018) )
oInstance := oServiceManager:createInstance(
cServiceName )
// ON ERROR &cOldErrHandler

// IF empty( oInstance )
// =__OOoReleaseCachedVars()
// oServiceManager := OOoGetServiceManager()
// oInstance := oServiceManager:createInstance(
cServiceName )
// ENDIF

RETURN(oInstance)

//function DoNothing__ErrorHandler( pnError, pcErrMessage,
pnLineNo,
pcProgramFileSys16, pcProgram, pcErrorParamSys2018 )
// local lRtn := .t.
//return(lRtn)

//PROCEDURE __OOoReleaseCachedVars()
// RELEASE goOOoServiceManager, goOOoDesktop,
goOOoCoreReflection
//ENDPROC

* Convert a local filename to an OOo URL.
FUNCTION OOoConvertToURL( cFilename )
LOCAL cURL

* Ensure leading slash.
IF LEFT( cFilename, 1 ) != "/"
cFileName := "/" + cFileName
ENDIF

cURL = strtran( cFilename, "\", "/" ) && change backslashes
to
forward slashes.
cURL = "file://" + cURL
RETURN(cURL)

/**********************************************
Code examples from:

http://www.oooforum.org/forum/viewtopic.phtml?p=28389#28389

***********************************************/

/* Example 1 ****************************

View previous topic :: View next topic
Author Message
DannyB
Moderator

Joined: 02 Apr 2003
Posts: 4071
Location: Lawrence, Kansas, USA
Posted: Sat Jan 17, 2004 10:21 am Post subject: Calc
Examples

-----------------------------------------------------------------------
---------

This is an example program that shows how to work with the Calc
spreadsheet.

This example program demonstrates....

1. How to obtain a Calc document by either....
1A. Creating a new one
1B. Opening one from disk (both Linux and Windows examples)
1C. Access the current Calc document, assuming that this macro is
embedded into a Calc document rather than some other type of
document.

2. Obtain a sheet from the document by either index or by name.

3. How to set formulas, strings, and numeric values in cells of
the
sheet. You can probably guess how to "get" values. (getFormula(),
getString(), getValue()). The example also sets dates into the
cells as
formulas.

4. Format date cells as Dates.

5. Add a chart to the document.

6. Find out how many sheets are in a calc document, add sheets,
or
remove sheets, change the name of a sheet.

7. Print a spreadsheet using three different techniques.

8. Save the Calc document in native OOo format.

9. Export the Calc document to... Excel, PDF, CSV, DIF, SYLK,
Html

Code:
Sub Main
' Set oDoc to which spreadsheet document we're working with.
' Three examples of how to set the variable oDoc...

'-----
' Set oDoc to the document that this macro is embedded into.
' This macro must be embedded into a Calc document.
' oDoc = ThisComponent
'-----

'-----
' Use this line to create a NEW calc document
' and assign it to variable oDoc.
oDoc = StarDesktop.loadComponentFromURL(
"private:factory/scalc",
"_blank", 0, Array() )
'-----

'-----
' Use this instead to open an EXISTING calc document,
' and assign it to variable oDoc.
' cFile = "C:\Documents and Settings\danny\Desktop\MyCalc" '
Windows
' cFile = "/home/danny/Desktop/MyCalc.sxc" ' Linux
' cURL = ConvertToURL( cFile + ".sxc" )
' oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0,
Array()
)
'-----

' Here are two ways to get access to one of the various
sheets
' in the spreadsheet document.
' Note that these don't make the sheet *vislble*, they merely
give
' access to the sheet's content within the program.
oSheet = oDoc.getSheets().getByIndex( 0 ) ' get the zero'th
sheet
' oSheet = oDoc.getSheets().getByName( "Sheet3" ) ' get by name

'-----
' Put some sales figures onto the sheet.
oSheet.getCellByPosition( 0, 0 ).setString( "Month" )
oSheet.getCellByPosition( 1, 0 ).setString( "Sales" )
oSheet.getCellByPosition( 2, 0 ).setString( "End Date" )

oSheet.getCellByPosition( 0, 1 ).setString( "Jan" )
oSheet.getCellByPosition( 0, 2 ).setString( "Feb" )
oSheet.getCellByPosition( 0, 3 ).setString( "Mar" )
oSheet.getCellByPosition( 0, 4 ).setString( "Apr" )
oSheet.getCellByPosition( 0, 5 ).setString( "May" )
oSheet.getCellByPosition( 0, 6 ).setString( "Jun" )
oSheet.getCellByPosition( 0, 7 ).setString( "Jul" )
oSheet.getCellByPosition( 0, 8 ).setString( "Aug" )
oSheet.getCellByPosition( 0, 9 ).setString( "Sep" )
oSheet.getCellByPosition( 0, 10 ).setString( "Oct" )
oSheet.getCellByPosition( 0, 11 ).setString( "Nov" )
oSheet.getCellByPosition( 0, 12 ).setString( "Dec" )

oSheet.getCellByPosition( 1, 1 ).setValue( 3826.37 )
oSheet.getCellByPosition( 1, 2 ).setValue( 3504.21 )
oSheet.getCellByPosition( 1, 3 ).setValue( 2961.45 )
oSheet.getCellByPosition( 1, 4 ).setValue( 2504.12 )
oSheet.getCellByPosition( 1, 5 ).setValue( 2713.98 )
oSheet.getCellByPosition( 1, 6 ).setValue( 2248.17 )
oSheet.getCellByPosition( 1, 7 ).setValue( 1802.13 )
oSheet.getCellByPosition( 1, 8 ).setValue( 2003.22 )
oSheet.getCellByPosition( 1, 9 ).setValue( 1502.54 )
oSheet.getCellByPosition( 1, 10 ).setValue( 1207.68 )
oSheet.getCellByPosition( 1, 11 ).setValue( 1319.71 )
oSheet.getCellByPosition( 1, 12 ).setValue( 786.03 )

oSheet.getCellByPosition( 2, 1 ).setFormula(
"=DATE(2004;01;31)" )
oSheet.getCellByPosition( 2, 2 ).setFormula(
"=DATE(2004;02;29)" )
oSheet.getCellByPosition( 2, 3 ).setFormula(
"=DATE(2004;03;31)" )
oSheet.getCellByPosition( 2, 4 ).setFormula(
"=DATE(2004;04;30)" )
oSheet.getCellByPosition( 2, 5 ).setFormula(
"=DATE(2004;05;31)" )
oSheet.getCellByPosition( 2, 6 ).setFormula(
"=DATE(2004;06;30)" )
oSheet.getCellByPosition( 2, 7 ).setFormula(
"=DATE(2004;07;31)" )
oSheet.getCellByPosition( 2, 8 ).setFormula(
"=DATE(2004;08;31)" )
oSheet.getCellByPosition( 2, 9 ).setFormula(
"=DATE(2004;09;30)" )
' Note that these last three dates are not set as DATE()
function
calls.
oSheet.getCellByPosition( 2, 10 ).setFormula( "10/31/2004" )
oSheet.getCellByPosition( 2, 11 ).setFormula( "11/30/2004" )
oSheet.getCellRangeByName( "C13" ).setFormula( "12/31/2004" )
'-----

'-----
' Format the date cells as dates.
oFormats = oDoc.getNumberFormats()
oLocale = createUnoStruct( "com.sun.star.lang.Locale" )
nDateKey = oFormats.getStandardFormat(
com.sun.star.util.NumberFormat.DATE, oLocale )
oCell = oSheet.getCellRangeByName( "C2:C13" )
oCell.NumberFormat = nDateKey
'-----

'-----
' Now add a chart to the spreadsheet.

oCellRangeAddress = oSheet.getCellRangeByName( "A1:B13"
).getRangeAddress()
' oCellRangeAddress = MakeCellRangeAddress( 0, 0, 1, 1, 12 )
' Get the collection of charts from the sheet.
oCharts = oSheet.getCharts()
' Add a new chart with a specific name,
' in a specific rectangle on the drawing page,
' and connected to specific cells of the spreadsheet.
oCharts.addNewByName( "Sales",_
MakeRectangle( 8000, 1000, 16000, 10000 ),_
Array( oCellRangeAddress ),_
True, True )
' From the collection of charts, get the new chart we just
created.
oChart = oCharts.getByName( "Sales" )
' Get the chart document model.
oChartDoc = oChart.getEmbeddedObject()

' Get the drawing text shape of the title of the chart.
oTitleTextShape = oChartDoc.getTitle()
' Change the title.
oTitleTextShape.String = "Sales Chart"

' Create a diagram.
oDiagram = oChartDoc.createInstance(
"com.sun.star.chart.BarDiagram" )
' Set its parameters.
oDiagram.Vertical = True
' Make the chart use this diagram.
oChartDoc.setDiagram( oDiagram )

' Ask the chart what diagram it is using.
' (Unnecessary, since variable oDiagram already contains this
value.)
oDiagram = oChartDoc.getDiagram()
' Make more changes to the diagram.
oDiagram.DataCaption =
com.sun.star.chart.ChartDataCaption.VALUE
oDiagram.DataRowSource =
com.sun.star.chart.ChartDataRowSource.COLUMNS
'
'-----

'-----
' Now demonstrate how to manipulate the sheets.

' Insert six more sheets into the document.
nNumSheetsCurrently = oDoc.getSheets().getCount()
oDoc.getSheets().insertNewByName( "Fred",
nNumSheetsCurrently+1 )
oDoc.getSheets().insertNewByName( "Joe",
nNumSheetsCurrently+2 )
oDoc.getSheets().insertNewByName( "Bill",
nNumSheetsCurrently+3 )
oDoc.getSheets().insertNewByName( "Sam",
nNumSheetsCurrently+4 )
oDoc.getSheets().insertNewByName( "Tom",
nNumSheetsCurrently+5 )
oDoc.getSheets().insertNewByName( "David",
nNumSheetsCurrently+6 )
' Now find a sheet named "Sheet2" and get rid of it.
oDoc.getSheets().removeByName( "Sheet2" )
' Now find the sheet named "Sam" and change its name to
"Sheet 37"
oDoc.getSheets().getByName( "Sam" ).Name = "Sheet 37"
'
'-----

'-------
' Now print the document -- three different ways.

' Technique 1.
' Now print the document.
' Print two copies.
' Print pages 1 thru 4, and also page 10.
' oDoc.print( _
' Array( _
' MakePropertyValue( "CopyCount", 2 ),_
' MakePropertyValue( "Pages", "1-4;10" ) ) )

' Technique 2.
' Print the document already, without any arguments.
' oDoc.print( Array() )

' Using technique 1 or 2, be sure not to close the document
' until printing is completed.
'
http://www.oooforum.org/forum/viewtopic.php?p=23144#23144

' Technique 3.
' Print the document by bringing up the Print Job dialog box
' for the user to interact with.
' oDocFrame = oDoc.getCurrentController().getFrame()
' oDispatchHelper = createUnoService(
"com.sun.star.frame.DispatchHelper" )
' oDispatchHelper.executeDispatch( oDocFrame, ".uno:Print", "",
0,
Array() )
' To learn some more about the dispatcher, see these
articles...
' http://www.oooforum.org/forum/viewtopic.php?t=5058
' http://www.oooforum.org/forum/viewtopic.php?t=5057

'
'-------

'-------
' Now save the document

' Prepare the filename to save.
' We're going to save the file in several different formats,
' but all based on the same filename.
cFile = "C:\Documents and Settings\dbrewer\Desktop\MyCalc" '
Windows
' cFile = "/home/danny/Desktop/MyCalc.sxc" ' Linux

' Now save the spreadsheet in native OOo Calc format.
cURL = ConvertToURL( cFile + ".sxc" )
oDoc.storeAsURL( cURL, Array() )

' Note the above used storeAsUrl,
' the following use storeToUrl.

' Now save it in Excel format.
cURL = ConvertToURL( cFile + ".xls" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName", "MS
Excel 97" ) ) )

' Now save a PDF.
cURL = ConvertToURL( cFile + ".pdf" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName",
"calc_pdf_Export" ) ) )

' Now save it in CSV format.
cURL = ConvertToURL( cFile + ".csv" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName",
"Text
- txt - csv (StarCalc)" ) ) )

' Now save it in DIF format.
cURL = ConvertToURL( cFile + ".dif" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName",
"DIF"
) ) )

' Now save it in SYLK format.
cURL = ConvertToURL( cFile + ".sylk" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName",
"SYLK" ) ) )

' Now save as HTML.
cURL = ConvertToURL( cFile + ".html" )
oDoc.storeToURL( cURL, Array( MakePropertyValue(
"FilterName",
"HTML
(StarCalc)" ) ) )

' A list of some filter names you can use for both loading
' and saving a document can be found here...
' http://www.oooforum.org/forum/viewtopic.php?t=3549

'
'-------

'-------
' Now close the document
' oDoc.close( True )
'-------
End Sub

'----------
' Create and return a new com.sun.star.beans.PropertyValue.
'
Function MakePropertyValue( Optional cName As String, Optional
uValue )
As com.sun.star.beans.PropertyValue
oPropertyValue = createUnoStruct(
"com.sun.star.beans.PropertyValue" )
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function

'----------
' Create and return a new com.sun.star.awt.Rectangle.
'
Function MakeRectangle( nX, nY, nWidth, nHeight ) As
com.sun.star.awt.Rectangle
oRectangle = createUnoStruct( "com.sun.star.awt.Rectangle" )
With oRectangle
.X = nX
.Y = nY
.Width = nWidth
.Height = nHeight
End With
MakeRectangle() = oRectangle
End Function

'----------
' Create and return a new com.sun.star.table.CellRangeAddress.
'
Function MakeCellRangeAddress( nSheetIndex, nStartColumn,
nStartRow,
nEndColumn, nEndRow ) As com.sun.star.table.CellRangeAddress
oCellRangeAddress = createUnoStruct(
"com.sun.star.table.CellRangeAddress" )
With oCellRangeAddress
.Sheet = nSheetIndex
.StartColumn = nStartColumn
.StartRow = nStartRow
.EndColumn = nEndColumn
.EndRow = nEndRow
End With
MakeCellRangeAddress() = oCellRangeAddress
End Function

Simply copy and paste the entire above code into OOo Basic's IDE
and
run
it. It is a self contained example.

This example is in OOo Basic.
This example appears later in this thread in other languages....
* Visual Basic
* Visual FoxPro
* Java
* Python
_________________
Want to make OOo Drawings like the colored flower design to the
left?

Last edited by DannyB on Sat Nov 20, 2004 2:42 pm; edited 7 times
in
total

*******************************************/

/* Example 2 **************************

Moderator

Joined: 02 Apr 2003
Posts: 4071
Location: Lawrence, Kansas, USA
Posted: Thu Apr 08, 2004 7:30 am Post subject:

-----------------------------------------------------------------------
---------

Here is a very similar Visual FoxPro example that.....
1. Creates an OOo Calc spreadsheet
2. Puts some strings into it.
3. Puts some numbers into it.
4. Puts some dates into it (as formulas)
5. Saves it in Calc format (as C:\Example.sxw)
6. Saves it in Excel format (as C:\Example.xls)
7. Closes the document -- but this line is commented to leave the
spreadsheet open in OOo

Code:
VfpOOoCalcExample()

PROCEDURE VfpOOoCalcExample()
* Create a spreadsheet.
LOCAL oDoc
oDoc = OOoOpenURL( "private:factory/scalc" )

* Get first sheet
LOCAL oSheet
oSheet = oDoc.getSheets().getByIndex( 0 )

*-----
* Put some sales figures onto the sheet.
oSheet.getCellByPosition( 0, 0 ).setString( "Month" )
oSheet.getCellByPosition( 1, 0 ).setString( "Sales" )
oSheet.getCellByPosition( 2, 0 ).setString( "End Date" )

oSheet.getCellByPosition( 0, 1 ).setString( "Jan" )
oSheet.getCellByPosition( 0, 2 ).setString( "Feb" )
oSheet.getCellByPosition( 0, 3 ).setString( "Mar" )
oSheet.getCellByPosition( 0, 4 ).setString( "Apr" )
oSheet.getCellByPosition( 0, 5 ).setString( "May" )
oSheet.getCellByPosition( 0, 6 ).setString( "Jun" )
oSheet.getCellByPosition( 0, 7 ).setString( "Jul" )
oSheet.getCellByPosition( 0, 8 ).setString( "Aug" )
oSheet.getCellByPosition( 0, 9 ).setString( "Sep" )
oSheet.getCellByPosition( 0, 10 ).setString( "Oct" )
oSheet.getCellByPosition( 0, 11 ).setString( "Nov" )
oSheet.getCellByPosition( 0, 12 ).setString( "Dec" )

oSheet.getCellByPosition( 1, 1 ).setValue( 3826.37 )
oSheet.getCellByPosition( 1, 2 ).setValue( 3504.21 )
oSheet.getCellByPosition( 1, 3 ).setValue( 2961.45 )
oSheet.getCellByPosition( 1, 4 ).setValue( 2504.12 )
oSheet.getCellByPosition( 1, 5 ).setValue( 2713.98 )
oSheet.getCellByPosition( 1, 6 ).setValue( 2448.17 )
oSheet.getCellByPosition( 1, 7 ).setValue( 1802.13 )
oSheet.getCellByPosition( 1, 8 ).setValue( 2203.22 )
oSheet.getCellByPosition( 1, 9 ).setValue( 1502.54 )
oSheet.getCellByPosition( 1, 10 ).setValue( 1207.68 )
oSheet.getCellByPosition( 1, 11 ).setValue( 1819.71 )
oSheet.getCellByPosition( 1, 12 ).setValue( 986.03 )

oSheet.getCellByPosition( 2, 1 ).setFormula(
"=DATE(2004;01;31)" )
oSheet.getCellByPosition( 2, 2 ).setFormula(
"=DATE(2004;02;29)" )
oSheet.getCellByPosition( 2, 3 ).setFormula(
"=DATE(2004;03;31)" )
oSheet.getCellByPosition( 2, 4 ).setFormula(
"=DATE(2004;04;30)" )
oSheet.getCellByPosition( 2, 5 ).setFormula(
"=DATE(2004;05;31)" )
oSheet.getCellByPosition( 2, 6 ).setFormula(
"=DATE(2004;06;30)" )
oSheet.getCellByPosition( 2, 7 ).setFormula(
"=DATE(2004;07;31)" )
oSheet.getCellByPosition( 2, 8 ).setFormula(
"=DATE(2004;08;31)" )
oSheet.getCellByPosition( 2, 9 ).setFormula(
"=DATE(2004;09;30)" )
* Note that these last three dates are not set as DATE()
function
calls.
oSheet.getCellByPosition( 2, 10 ).setFormula( "10/31/2004" )
oSheet.getCellByPosition( 2, 11 ).setFormula( "11/30/2004" )
oSheet.getCellRangeByName( "C13" ).setFormula( "12/31/2004" )
*-----

* Format the date cells as dates.
oFormats = oDoc.getNumberFormats()
oLocale = OOoCreateStruct( "com.sun.star.lang.Locale" )
* com.sun.star.util.NumberFormat.DATE = 2
nDateKey = oFormats.getStandardFormat( 2, oLocale )
oCell = oSheet.getCellRangeByName( "C2:C13" )
oCell.NumberFormat = nDateKey

LOCAL ARRAY aOneArg[1]
LOCAL cFile, cURL

* cFile = GetDesktopFolderPathname()+"example"
cFile = "c:\example"

* Now save the spreadsheet.
cURL = OOoConvertToURL( cFile + ".sxw" )
aOneArg[1] = OOoMakePropertyValue( "Overwrite", .T. )
oDoc.storeToUrl( cURL, @ aOneArg )

* Now save it as Excel
cURL = OOoConvertToURL( cFile + ".xls" )
aOneArg[1] = OOoMakePropertyValue( "FilterName", "MS Excel
97" )
oDoc.storeToUrl( cURL, @ aOneArg )

* Close the document.
* oDoc.close( 1 ) && TRUE
ENDPROC

* Open or Create a document from it's URL.
* New documents are created by URL's such as:
* private:factory/sdraw
* private:factory/swriter
* private:factory/scalc
* private:factory/simpress
FUNCTION OOoOpenURL( cURL )
* LOCAL oPropertyValue
* oPropertyValue = OOoCreateStruct(
"com.sun.star.beans.PropertyValue" )

* LOCAL ARRAY aNoArgs[1]
* aNoArgs[1] = oPropertyValue
* aNoArgs[1].Name = "ReadOnly"
* aNoArgs[1].Value = .F.

* These two lines replace the alternate version above,
* which are left commented for the insight they provide.
LOCAL ARRAY aNoArgs[1]
aNoArgs[1] = OOoMakePropertyValue( "Hidden", .F. )

LOCAL oDesktop
oDesktop = OOoGetDesktop()

LOCAL oDoc
oDoc = oDesktop.LoadComponentFromUrl( cURL, "_blank", 0, @
aNoargs
)

* Make sure that arrays passed to this document are passed
zero
based.
COMARRAY( oDoc, 10 )

RETURN oDoc
ENDFUNC

* Create a com.sun.star.beans.PropertyValue struct and return it.
FUNCTION OOoMakePropertyValue( cName, uValue, nHandle, nState )
LOCAL oPropertyValue
oPropertyValue = OOoCreateStruct(
"com.sun.star.beans.PropertyValue" )

oPropertyValue.Name = cName
oPropertyValue.Value = uValue

IF TYPE([nHandle])="N"
oPropertyValue.Handle = nHandle
ENDIF
IF TYPE([nState])="N"
oPropertyValue.State = nState
ENDIF

RETURN oPropertyValue
ENDFUNC

* Sugar coated routine to create any UNO struct.
* Use the Bridge_GetStruct() feature of the OLE-UNO bridge.
FUNCTION OOoCreateStruct( cTypeName )
LOCAL oServiceManager
oServiceManager = OOoGetServiceManager()

LOCAL oStruct
oStruct = .NULL.

LOCAL cOldErrHandler
cOldErrHandler = ON( "ERROR" )
ON ERROR = DoNothing__ErrorHandler( ERROR(), MESSAGE(),
LINENO(),
SYS(16), PROGRAM(), SYS(2018) )
oStruct = oServiceManager.Bridge_GetStruct( cTypeName )
ON ERROR &cOldErrHandler

IF ISNULL( oStruct )
=__OOoReleaseCachedVars()
oServiceManager = OOoGetServiceManager()
oStruct = oServiceManager.Bridge_GetStruct( cTypeName )
ENDIF

RETURN oStruct
ENDFUNC

* Return the OpenOffice.org desktop object.
* Cache it in a global variable.
* Create it if not already cached.
FUNCTION OOoGetDesktop()
IF (TYPE([goOOoDesktop])!="O") OR ISNULL( goOOoDesktop )
PUBLIC goOOoDesktop
goOOoDesktop = OOoServiceManager_CreateInstance(
"com.sun.star.frame.Desktop" )
COMARRAY( goOOoDesktop, 10 )
ENDIF
RETURN goOOoDesktop
ENDFUNC

* Return the OpenOffice.org service manager object.
* Cache it in a global variable.
* Create it if not already cached.
FUNCTION OOoGetServiceManager()
IF (TYPE([goOOoServiceManager])!="O") OR ISNULL(
goOOoServiceManager )
PUBLIC goOOoServiceManager
goOOoServiceManager = CREATEOBJECT(
"com.sun.star.ServiceManager" )
ENDIF
RETURN goOOoServiceManager
ENDFUNC

* Sugar coated routine to ask the service manager to
* create you an instance of some other OpenOffice.org UNO
object.
FUNCTION OOoServiceManager_CreateInstance( cServiceName )
LOCAL oServiceManager
oServiceManager = OOoGetServiceManager()

LOCAL oInstance
oInstance = .NULL.

LOCAL cOldErrHandler
cOldErrHandler = ON( "ERROR" )
ON ERROR = DoNothing__ErrorHandler( ERROR(), MESSAGE(),
LINENO(),
SYS(16), PROGRAM(), SYS(2018) )
oInstance = oServiceManager.createInstance( cServiceName )
ON ERROR &cOldErrHandler

IF ISNULL( oInstance )
=__OOoReleaseCachedVars()
oServiceManager = OOoGetServiceManager()
oInstance = oServiceManager.createInstance( cServiceName )
ENDIF

RETURN oInstance
ENDFUNC

PROCEDURE DoNothing__ErrorHandler( pnError, pcErrMessage,
pnLineNo,
pcProgramFileSys16, pcProgram, pcErrorParamSys2018 )
ENDPROC

PROCEDURE __OOoReleaseCachedVars()
RELEASE goOOoServiceManager, goOOoDesktop,
goOOoCoreReflection
ENDPROC

* Convert a local filename to an OOo URL.
FUNCTION OOoConvertToURL( cFilename )
* Ensure leading slash.
IF LEFT( cFilename, 1 ) != "/"
cFileName = "/" + cFileName
ENDIF

LOCAL cURL
cURL = CHRTRAN( cFilename, "\", "/" ) && change backslashes
to
forward slashes.
cURL = "file://" + cURL
RETURN cURL
ENDFUNC

The function VfpOOoCalcExample() is actually the heart of the
example.

Everything else after VfpOOoCalcExample() is just stuff ripped
from my
general purpose OOo Library in VFP.

This was tested in VFP 8 and VFP 7. It should work in VFP 6, but
not
tested. It may work in VFP 5, but I have reason to believe that
it
might
not. It will definitely not work in VFP 3.
_________________
Want to make OOo Drawings like the colored flower design to the
left?

******************/

--
Regards
------------------------------
Gerald Drouillard
Technology Consultant
Drouillard & Associates, Inc.
http://www.Drouillard.ca

<END QUOTE>

May be close enough that you can service your need, even though
it is not exactly xHarbour.

David A. Smith


jogabar

unread,
Nov 2, 2007, 12:36:26 AM11/2/07
to
Not work. Program only call Calc of openoffice if have session
normal, but not in Scheduled Task.


The problem is:

oServiceManager := TOleAuto():New("com.sun.star.ServiceManager")

Not work in Scheduled Task.


Thanks

On 26 oct, 23:34, "N:dlzc D:aol T:com \(dlzc\)" <dl...@cox.net> wrote:
> Dear jogabar:
>
> "jogabar" <jorge.gar...@gmail.com> wrote in message
>
> news:1193451285....@57g2000hsv.googlegroups.com...
>
>
>
>
>


> Provided by Klas Engwall, December 2006 on the old news server:
> <QUOTE>

> Go tohttp://api.openoffice.org/and look for the link to the

Raimundo Machado de Morais Neto

unread,
Mar 30, 2022, 10:42:19 AM3/30/22
to
Bom dia,

se eu quisesse que a pagina ficasse em LANDSCAPE

faria como??


oPageStyle := oServiceManager:Bridge_Struct("com.sun.star.text.PagePrintSettings")
oPageStyle:isLandscape := .T.

Funciona assim???
0 new messages