Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionGet Free, , ReadFile
ReadFile = Mid$(ReadFile, InStr(1, ReadFile, "<TR>"))
Option Explicit Private Sub Form_Load() Dim sFile As String Dim sBuffer As String Dim sText As String Dim asCol() As String Dim sColor As String Dim i As Integer Dim j As Integer ' récupération contenu du html sFile = ReadFile(App.Path & "\Y.html") ' cherche les 1er TR et supprime ce qu'il y a avant sFile = Mid$(sFile, InStr(1, sFile, "<TR>")) ' supprime toutes les qui ne servent à rien et qui ne sont même pas fermées sFile = Replace(sFile, "", vbNullString) ' on récupère tous les tronçons TR, en boucle, toujours en supprimant le texte récupéré i = 0 Do While InStr(1, sFile, "<TR>" & vbCrLf) sBuffer = MyMid(sFile, "<TR>" & vbCrLf, "</TR>") 'Debug.Print "¤" & sBuffer & "¤" sFile = Mid$(sFile, InStr(1, sFile, "<TR>") + 1 + Len(sBuffer)) i = i + 1 ' i=1 => header. sinon champs If i = 1 Then ' supprime les et récupère toutes les colonnes sBuffer = Replace(sBuffer, "", vbNullString) sBuffer = Replace(sBuffer, "", vbNullString) asCol = Split(sBuffer, "/TD>") For j = 0 To UBound(asCol) - 1 ' nouvelle colonne sColor = MyMid(asCol(j), "#", " ") sText = MyMid(asCol(j), ">", "<") With MSFlexGrid1 .Rows = 1 .Cols = j + 1 .ColWidth(j) = 2000 .Row = 0 .Col = j .Text = sText .CellFontBold = True .CellBackColor = GetOleColorFromHtmlColor("#" & sColor) End With Next j Else asCol = Split(sBuffer, "/TD>") ' colonne de gauche sColor = MyMid(asCol(0), "#", " ") sText = MyMid(asCol(0), " ", " ") With MSFlexGrid1 .Rows = .Rows + 1 .Row = .Rows - 1 .Col = 0 .Text = sText .CellFontBold = True .CellBackColor = GetOleColorFromHtmlColor("#" & sColor) ' texte des autres cellules For j = 1 To UBound(asCol) - 1 sColor = MyMid(asCol(j), "#", " ") sText = MyMid(asCol(j), ">", "<") .Col = .Col + 1 .Text = sText .CellBackColor = GetOleColorFromHtmlColor("#" & sColor) Next j End With End If Loop End Sub '---------------------------------------------------------------- ' LIRE LA TOTALITÉ DU CONTENU D'UN FICHIER ' http://www.codyx.org/snippet_lire-totalite-contenu-fichier_47.aspx#133 '---------------------------------------------------------------- Private Function ReadFile(ByVal FileName As String) As String Dim Free As Integer Free = FreeFile() Open FileName For Binary As Free ReadFile = String(LOF(1), 0) Get Free, , ReadFile Close Free End Function '---------------------------------------------------------------- '---------------------------------------------------------------- ' RÉCUPÉRER UNE CHAÎNE (INCONNUE) PLACÉE ENTRE DEUX CHAÎNES (CONNUES) ' http://www.codyx.org/snippet_recuperer-chaine-inconnue-placee-entre-deux-chaines-connues_334.aspx#1043 '---------------------------------------------------------------- Private Function MyMid(ByRef Expression As String, sLeft As String, sRight As String, Optional Start As Long = 1) As String Dim lPosL As Long, lPosR As Long lPosL InStr(Start, Expression, sLeft): lPosR InStr(lPosL + 1, Expression, sRight) If lPosL > 0 And lPosR > 0 Then MyMid = Mid$(Expression, lPosL + Len(sLeft), lPosR - lPosL - Len(sLeft)) Else MyMid = vbNullString End If End Function '---------------------------------------------------------------- '---------------------------------------------------------------- ' CONVERTIR UNE COULEUR LONG EN CODE HTML (ET VICE VERSA) ' http://www.codyx.org/snippet_convertir-couleur-long-code-html-vice-versa_254.aspx#818 '---------------------------------------------------------------- Private Function GetOleColorFromHtmlColor(ByVal sCol As String) As OLE_COLOR sCol = RightB$(sCol, LenB(sCol) - 2) sCol = Right$(sCol, 2) & Mid$(sCol, 3, 2) & Left$(sCol, 2) GetOleColorFromHtmlColor = CLng("&H00" & sCol) End Function '----------------------------------------------------------------