IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

[VB.Net] lecture de fichier EXCEL


Sujet :

Windows Forms

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Octobre 2006
    Messages : 2
    Points : 1
    Points
    1
    Par défaut [VB.Net] lecture de fichier EXCEL
    Bonjour,

    J'ai besoin de l'ire un fichier EXCEL de façon à remplir une table Oracle.

    Pour cela, j'essaie d'ouvrir un fichier Excell. j'ai donc écris les lignes suivants :

    Dim xlapp As Excel.Application
    Dim xlSheet As Excel.Worksheet

    xlapp = New Excel.Application
    xlSheet = xlapp.Workbooks.Open("C:\Monfich.xls").Worksheets(0)

    Ceci génère une erreur.
    Pour info, j'ais uniquement installé sur mon PC Microsoft Excel 9.0 Object libray.


    Pouvez vous me dire ce qui ne va pas.

    Merci

  2. #2
    Membre éprouvé
    Avatar de HULK
    Inscrit en
    Juillet 2003
    Messages
    1 274
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 274
    Points : 1 280
    Points
    1 280
    Par défaut
    c'est quoi le message d'erreur ?
    j'suis vert !

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Octobre 2006
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Voila le stack de mon erreur :

    System.Runtime.InteropServices.COMException was unhandled
    ErrorCode=-2147319784
    Message="Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"
    Source="Interop.Excel"
    StackTrace:
    at Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru)
    at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\pxcc721\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb:line 8
    at System.EventHandler.Invoke(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
    at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Control.set_Visible(Boolean value)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()

  4. #4
    Membre éprouvé
    Avatar de HULK
    Inscrit en
    Juillet 2003
    Messages
    1 274
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 274
    Points : 1 280
    Points
    1 280
    Par défaut
    mets un try catch avec ex.message pour capter le message d'erreur, on en aura un moins compliqué je pense
    j'suis vert !

  5. #5
    jab
    jab est déconnecté
    Rédacteur
    Avatar de jab
    Homme Profil pro
    SharePoint developpeur
    Inscrit en
    Février 2004
    Messages
    1 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : Belgique

    Informations professionnelles :
    Activité : SharePoint developpeur
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 1 173
    Points : 4 339
    Points
    4 339
    Par défaut
    Je n'ai aucune expérience avec mais dans ton cas ne serait-il pas plus simple dans ton cas d'utiliser le driver Excel ODBC au lieu d'ouvrir excel en oledb ?

  6. #6
    Candidat au Club
    Inscrit en
    Octobre 2006
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    Dim xlApp As Object
    Dim xlBook As Object
    Dim xlSheet As Object

    xlApp = CreateObject("Excel.Application")
    ( ou si tu préfère New Excel.Application ! )
    xlBook = xlApp.Workbooks.open("C:\Monfich.xls").
    xlSheet = xlBook.Worksheets(ici le nom ou N° de feuille)

    Es-tu sûr du 0 dans "Worksheets(0)", étonnant !

    Ca marche, c'est sûr.

    Gilles_37

Discussions similaires

  1. [Débutant] Lecture + Manipulation fichier Excel sous VB.net
    Par MelMon dans le forum VB.NET
    Réponses: 6
    Dernier message: 18/03/2013, 22h09
  2. [VB.NET] Lire un Fichiers Excel
    Par kanzarih dans le forum VB.NET
    Réponses: 4
    Dernier message: 25/06/2009, 20h15
  3. {VBA Excel}Question sur la lecture de fichier excel
    Par Thomas69 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 11/12/2007, 09h12
  4. [lecture/ecriture] fichier excel
    Par ethno dans le forum C
    Réponses: 4
    Dernier message: 14/04/2006, 19h47
  5. Problème de lecture de fichier Excel
    Par cocaetjusdorange dans le forum Langage
    Réponses: 4
    Dernier message: 08/02/2006, 11h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo