1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Public Sub export(Format As String)
Dim Fichier As String
Dim classeur, feuilles, feuille1, Cell As Object
Dim name As String = "Export_" & " " & Replace(Today.Date, " / ", " - ") & ".ods"
ConnectOpenOffice()
Fichier = My.Computer.FileSystem.SpecialDirectories.Desktop & " \ " & name
Fichier = ConvertToURL(Fichier)
classeur = StarDesktop.LoadComponentFromURL(Fichier, "_blank", 0, dummyArray)
feuilles = classeur.Sheets
feuille1 = feuilles.getByName("Feuille1")
Cell = feuille1.getCellByPosition(colonne, ligne)
Cell.String = "test"
DisconnectOpenOffice(1)
End Sub
Sub ConnectOpenOffice()
If IsOpenOfficeConnected() Then Exit Sub
Try
OpenOffice = CreateObject("com.sun.star.ServiceManager")
Catch
OpenOffice = Nothing
End Try
If isNullEmpty(OpenOffice) Then
Err.Raise(vbObjectError + OOoErrorN, "OpenOffice", OOo_connectKO)
Else
StarDesktop = CreateUnoService("com.sun.star.frame.Desktop")
OOoIntrospection = CreateUnoService("com.sun.star.beans.Introspection")
OOoDisp = CreateUnoService("com.sun.star.frame.DispatchHelper")
OOoTypeDescrMngr = OpenOffice.DefaultContext.getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager")
End If
End Sub
Sub DisconnectOpenOffice(Optional ByVal closeOpenOffice As Integer = 0)
Dim collDocs As Object
Dim ooo As Object, dtp As Object
If (closeOpenOffice = -1) Or (closeOpenOffice = 1) Then
collDocs = StarDesktop.Components.createEnumeration()
If collDocs.hasMoreElements Then closeOpenOffice = 0
collDocs = Nothing
End If
OOoIntrospection = Nothing
OOoDisp = Nothing
OOoTypeDescrMngr = Nothing
StarDesktop = Nothing
OpenOffice = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
If closeOpenOffice <> 0 Then
ooo = CreateObject("com.sun.star.ServiceManager")
dtp = ooo.createInstance("com.sun.star.frame.Desktop")
If closeOpenOffice = 2 Then dtp.SuspendQuickStartVeto = True
dtp.terminate()
dtp = Nothing
ooo = Nothing
End If
End Sub
Public Const OOo_connectKO = "OpenOffice connection is impossible" |
Partager