Take care because the program was written on a french computer so the name of the first sheets in the workbook is "Feuille1" and on other foreigner language "Feuil1" and that's generate a crash so in this case modify the following instruction
Code: Select all
EnableExplicit
Define.l oSM, oDesk, oDoc,mafeuille,lesfeuille,mycell
;'Les objets de base pour travailler avec OOo
Declare MakePropertyValue(cName.s, uValue.b)
Declare MakePropertyValue1(cName.s, uValue.s)
Declare.s ConvertToUrl(strFile.s)
XIncludeFile "DispHelper_Include.pb"
XIncludeFile "VariantHelper_Include.pb"
Define.safearray *openpar
Define.variant openarray
*openpar = saCreateSafeArray(#VT_DISPATCH, 0, 3)
SA_DISPATCH(*openpar, 0) = MakePropertyValue("ReadOnly", #True)
SA_DISPATCH(*openpar, 1) = MakePropertyValue1("Password", "secret
SA_DISPATCH(*openpar, 2) = MakePropertyValue("Hidden", #False)
V_ARRAY_DISP(openarray) = *openpar
dhInitializeImp()
dhToggleExceptions(#True)
Define.variant wert1, wert2, wert3, result, text
V_DOUBLE(wert1) = 3.33333333333333
V_DOUBLE(wert2) = 4.44444444444444
V_DOUBLE(wert3) = 5.55555555555555
V_STR(text) = T_BSTR("Hallo Welt")
;'Instancie OOo : ces deux lignes sont obligatoires avec VB dans tout code !
oSM = dhCreateObject("com.sun.star.ServiceManager")
dhGetValue("%o",@oDesk,oSM, ".createInstance(%T)", @"com.sun.star.frame.Desktop")
dhGetValue("%o",@oDoc, oDesk,".loadComponentFromURL(%T,%T,%d,%v)",@"private:factory/scalc", @"_blank",0, openarray)
dhGetValue("%o",@mafeuille, odoc ,".Sheets.getByName(%T)",@"Feuille1")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"A1")
dhPutValue(Mycell, ".String = %T", @"Feel")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"B1")
dhPutValue(Mycell, ".String = %T", @"the")
dhGetValue("%o", @mycell, mafeuille,".getCellRangeByName(%T", @"C1")
dhPutValue(Mycell, ".String = %T", @"pure")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"D1")
dhPutValue(Mycell, ".String = %T", @"Power")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"A2")
dhPutValue(Mycell, ".String = %T", @"The")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"A3")
dhPutValue(Mycell, ".String = %T", @"Pure")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"A4")
dhPutValue(Mycell, ".String = %T", @"Power")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"B2")
dhPutValue(Mycell, ".value = %v", wert1)
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"B3")
dhPutValue(Mycell, ".value = %v", wert2)
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"B4")
dhPutValue(Mycell, ".value = %v", wert3)
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"C2")
dhPutValue(Mycell, ".String = %v", text)
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T", @"B2")
dhGetValue("%v", @result, Mycell, ".Value")
MessageRequester("PureDispHelper-ExcelDemo", "Result Cells(2,2): " + VT_STR(result))
MessageRequester("PureDispHelper-ExcelDemo", "Click OK to close Open Office")
dhCallMethod(odoc,".close(%b)",#True)
dhUninitialize()
End
Procedure MakePropertyValue(cName.s, uValue.b)
Define oStruct.l
Define oServiceManager.l = dhCreateObject("com.sun.star.ServiceManager")
dhGetValue("%o", @oStruct, oServiceManager, ".Bridge_GetStruct(%T)", @"com.sun.star.beans.PropertyValue")
dhPutValue(oStruct, ".Name=%T", @cName)
dhPutValue(oStruct, ".Value=%b", @uValue)
ProcedureReturn oStruct
EndProcedure
Procedure MakePropertyValue1(cName.s, uValue.s)
Define oServiceManager.l
Define ostruct
oServiceManager = dhCreateObject("com.sun.star.ServiceManager")
dhGetValue("%o", @oStruct, oServiceManager, ".Bridge_GetStruct(%T)", @"com.sun.star.beans.PropertyValue")
dhPutValue(oStruct, ".Name=%T", @cName)
dhPutValue(oStruct, ".Value=%T", @uValue)
ProcedureReturn oStruct
EndProcedure
Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile= ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strfile
ProcedureReturn strFile
EndProcedure