rufo |
Dost67 a écrit a écrit :
N'y a t-il pas la possibilité le programme en exe plutôt et de l'utiliser avec CGI... mais bon là je sais pas trop comment ça fonctionne.
|
non, pas besoin de cgi... notre dll, on l'a faite en VB, et on utilise les fct de word. mais on a du se tromper, ça marche pas :(
qq'un verrait où y'a une erreur (en dehors du fait qu'on écrit de temps en temps dans un fichier txt pour débugger)
Sub SplitFile2Html(NomFichier As String, CheminEnrgt As String)
' Déclaration des variables
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim oWordDocTmp As Word.Document
Dim oFso 'As New FileSystemObject
Dim oText 'As New TextStream
Dim strFile As String
Dim nbPages As Integer
Dim i As Integer
' Création de l'application et ouverture du fichier
Set oWordApp = CreateObject("Word.Application" )
Set oWordDoc = oWordApp.Documents.Open(FileName:=NomFichier, ConfirmConversions:=False, ReadOnly:=True)
' Nombre de pages
nbPages = oWordDoc.ComputeStatistics(Statistic:=wdStatisticPages)
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 2)
oText.write ("Debut" & i & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
' On s'occupe des n-1 premières pages
For i = 1 To nbPages - 2
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Page : " & i & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
' On copie la page
With oWordApp.Selection
.Extend
.GoTo (wdGoToPage)
.Copy
.Collapse (wdCollapseEnd)
End With
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Copie ok" & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
' On crée un nouveau document et on colle la page dedans
Set oWordDocTmp = oWordApp.Documents.Add
oWordApp.Selection.Paste
oWordDocTmp.SaveAs FileName:=CheminEnrgt & "\" & CStr(i) & ".html", FileFormat:=wdFormatHTML
oWordDocTmp.Close
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Paste ok" & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
' On réouvre le fichier pour mettre à jour les chemins
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile(CheminEnrgt & "\" & CStr(i) & ".html", 1)
strFile = oText.ReadAll
oText.Close
strFile = Replace(strFile, "./" & CStr(i) & ActiveDocument.WebOptions.FolderSuffix, "../" & Mid(CheminEnrgt, InStr(CheminEnrgt, "Fichiers" )) & "/" & CStr(i) & ActiveDocument.WebOptions.FolderSuffix)
Set oText = oFso.OpenTextFile(CheminEnrgt & "\" & CStr(i) & ".html", 2)
oText.write (strFile)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Replace ok" & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
Next
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Fin boucle" & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
' On s'occupe de la dernière page
'With oWordApp.Selection
' .MoveEnd Unit:=wdParagraph, Count:=15
' .Copy
'End With
' On crée un nouveau document et on colle la page dedans
'Set oWordDocTmp = oWordApp.Documents.Add
'oWordApp.Selection.Paste
'oWordDocTmp.SaveAs FileName:=CheminEnrgt & "\" & CStr(i) & ".html", FileFormat:=wdFormatHTML
'oWordDocTmp.Close
'Set oWordDocTmp = Nothing
' On réouvre le fichier pour mettre à jour les chemins
'Set oFso = CreateObject("Scripting.FileSystemObject" )
'Set oText = oFso.OpenTextFile(CheminEnrgt & "\" & CStr(i) & ".html", 1)
'strFile = oText.ReadAll
'oText.Close
'strFile = Replace(strFile, "./" & CStr(i) & ActiveDocument.WebOptions.FolderSuffix, "../" & Mid(CheminEnrgt, InStr(CheminEnrgt, "Fichiers" )) & "/" & CStr(i) & ActiveDocument.WebOptions.FolderSuffix)
'Set oText = oFso.OpenTextFile(CheminEnrgt & "\" & CStr(i) & ".html", 2)
'oText.write (strFile)
'oText.Close
'Set oText = Nothing
'Set oFso = Nothing
' Fermeture du fichier et de l'application
'oWordDoc.Close
'oWordApp.Quit
Set oWordDoc = Nothing
Set oWordApp = Nothing
' ************* DEBUG ******************
Set oFso = CreateObject("Scripting.FileSystemObject" )
Set oText = oFso.OpenTextFile("C:\infos.txt", 8)
oText.write ("Bye" & vbCrLf)
oText.Close
Set oText = Nothing
Set oFso = Nothing
' ************* DEBUG ******************
End Sub
le pb, c'est que la dll plante sur la convertion de la dernière page du rtf -> html... |