Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1726 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [VBS] Lire un fichier excel

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[VBS] Lire un fichier excel

n°1974692
b0ugie
Cyber-DeepCloud Instructor
Posté le 17-03-2010 à 17:43:51  profilanswer
 

Bonjour
 
Je travaille actuellement sur la réalisation d'un script qui genere un fichier html contenant un tableau à partir d'une feuille excel .xls .
 
J'ai produit ce code :
 
 

Dim xlsFile, filePath, strPage
 
Const ForWriting = 2
 
xlsFile = "monplaning.xls"
filePath = Replace(WScript.ScriptFullName, WScript.ScriptName, "" )
 
Set conn = Wscript.CreateObject("ADODB.Connection" )
Set rs = Wscript.CreateObject("ADODB.Recordset" )
 
str = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=" & filePath  & xlsFile
conn.Open str
 
sNameSheet = "Feuil1"
sCells = "A1:H3"
 
SQL = "SELECT * from `" & sNameSheet & "$" & sCells & "`"
rs.Open SQL, conn
 
strPage = "<html>" & vbCrLf & _
    "    <head>" & vbCrLf & _
    "        <title>Planing 2010</title>" & vbCrLf & _
    "        <style type=""text/css"">" & vbCrLf & _
    "            table { border: 1px solid black; border-collapse:collapse; }" & vbCrLf & _
    "            td { border: 1px solid black; width: 30px; text-align: center; }" & vbCrLf & _
    "        </style>" & vbCrLf & _
    "    </head>" & vbCrLf & _
    "    <body>" & vbCrLf & _
    "        <table>" & vbCrLf
 
do while not rs.eof
    strPage = strPage & "            <tr>" & vbCrLf
    for each field in rs.fields
        If IsNull(field.value) Then
            strPage = strPage & "                <td></td>" & vbCrLf
        Else
            strPage = strPage & "                <td>" & field & "</td>" & vbCrLf
        End If
    next
    strPage = strPage & "            </tr>" & vbCrLf
    rs.moveNext()
loop
strPage = strPage & "        </table>" & vbCrLf
strPage = strPage & "    </body>" & vbCrLf
strPage = strPage & "</html>" & vbCrLf
 
Set fso = CreateObject("Scripting.FileSystemObject" )
Set f = fso.OpenTextFile(PATH & "index.html", ForWriting, true)
f.write(strPage)
 
rs.close
conn.close
f.close
set rs=nothing
set conn=nothing


 
 
Si on test mon code avec la feuille excel ci dessous :
http://img138.imageshack.us/img138/1222/bugado.jpg
 
On arrive à un resultat comme celui la :
http://img146.imageshack.us/img146/6076/bugado2.jpg
 
On s'aperçoit que seul les colonnes avec les cellules de même type (text ou entier) s'affichent.
 
Exist-il un remede contre ce probleme ?
 
Merci d'avance pour vos réponses.


---------------
Une femme c'est temporaire - une ex c'est pour la vie.
mood
Publicité
Posté le 17-03-2010 à 17:43:51  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [VBS] Lire un fichier excel

 

Sujets relatifs
[VBA] lire fichier texte jusqu'à ...case in blabla (KSH) ===> fichier CSV
probleme excel[Flash] Masquage selon fichier PNG
couper une facture vers un fichier clientBasique:Sélection Worksheet Excel depuis une macro ?
Déplacer une ligne de code dans un fichier XML ?Simulation de Alt tab sous VBA (Excel)
[VBA] Excel: propriété ForeColor d'un UserForm 
Plus de sujets relatifs à : [VBS] Lire un fichier excel


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR