COMatePLUS und OpenOffice.org
Verfasst: 05.09.2010 13:16
Hallo,
seit ein paar Tagen versuche ich ein OpenOffice Calc – Dokument, das ich mit PB und COMatePLUS erzeugt habe, als Excel-Datei abzuspeichern. Das Speichern als Calc (ods) habe ich mittlerweile hin bekommen, aber der Export in ein Fremdformat will einfach nicht funktionieren.
Der Code für das Erzeugen und Speichen eines Calc-Dokuments stammt zum größten Teil aus den Beispielen des englischen Forums.
Vielen Dank für eure Hilfe
seit ein paar Tagen versuche ich ein OpenOffice Calc – Dokument, das ich mit PB und COMatePLUS erzeugt habe, als Excel-Datei abzuspeichern. Das Speichern als Calc (ods) habe ich mittlerweile hin bekommen, aber der Export in ein Fremdformat will einfach nicht funktionieren.
Der Code für das Erzeugen und Speichen eines Calc-Dokuments stammt zum größten Teil aus den Beispielen des englischen Forums.
Code: Alles auswählen
XIncludeFile "COMatePLUS.pbi"
XIncludeFile "VariantHelper_Include.pbi"
Procedure.S ConvertToUrl(strFile.S)
strFile = ReplaceString(strFile, "", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile = ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strFile
ProcedureReturn strFile
EndProcedure
Define.COMateObject oSM, oDesk, oCalc, oSheet, oCell
Define.safearray *openpar
Define.variant openarray
Define.variant value_pi_double
Define.d result
V_ARRAY_DISP(openarray) = safearray
V_DOUBLE(value_pi_double) = 3.1415926
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
*openpar = saCreateSafeArray(#VT_DISPATCH, 0, 3)
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
;Creating instance of Desktop
oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
If oDesk
;Opening a new calc Document
load.S = "loadComponentFromURL('private:factory/scalc', '_blank', 0, " + Str(openarray) + " as variant)"
Debug load
oCalc = oDesk\GetObjectProperty(load.S)
If oCalc
oSheet = oCalc\GetObjectProperty("Sheets\getByName('Tabelle1')")
If oSheet
oCell = oSheet\GetObjectProperty("getCellRangeByName('A3')")
oCell\SetProperty("String = 'Hello World1 !' as string")
oCell = oSheet\GetObjectProperty("getCellRangeByName('A1')")
datums.S = FormatDate("%hh:%ii:%ss", Date())
oCell\SetProperty("String = '"+datums.S+"' as string")
oCell = oSheet\GetObjectProperty("getCellRangeByName('B5')")
oCell\SetProperty("value = "+Str(value_pi_double)+" as variant")
Debug COMate_GetLastErrorDescription()
oSheet\Release()
EndIf
url.S = ConvertToUrl("C:/temp/test.ods")
saveFile.S = "storeToURL('"+url+"' " +", "+ Str(openarray) + " As variant)"
oCalc\Invoke(saveFile)
Delay(100)
oCalc\Invoke("dispose")
oCalc\Release()
EndIf
oDesk\Release()
EndIf
oSM\Release()
EndIf
End