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

Contribuez .NET Discussion :

[c#] Manipuler Excel


Sujet :

Contribuez .NET

  1. #1
    Nouveau membre du Club Avatar de Louisa
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    54
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2006
    Messages : 54
    Points : 36
    Points
    36
    Par défaut [c#] Manipuler Excel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    using Microsoft.Office.Interop.Excel;
    
    
     public Microsoft.Office.Interop.Excel.ApplicationClass oExcelApp;
            public Microsoft.Office.Interop.Excel.Workbooks oBooks;
            public Microsoft.Office.Interop.Excel.Workbook oBook;
            public Microsoft.Office.Interop.Excel.Worksheet oSheet;
            public void ExportVersExcel()
            {
                oExcelApp = null;
                oBooks = null;
                oBook = null;
                oSheet = null;
                 // Créer l’objet Excel             oExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); 
                oExcelApp.Visible = true; // l’afficher  ou pas
                oBooks = oExcelApp.Workbooks; 
                //ouvrir le fichier Excel désiré 
                oBook = oBooks.Open(nomfichier, Missing.Value ,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value,Missing.Value);
               // on active la feuille            oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oExcelApp.ActiveSheet;
                // on active la feuille auto            oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oExcelApp.Sheets.get_Item("auto");
                 // lancement d' une macro            object ret = oExcelApp.Application.Run("macro1", Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value);
                 ///trouver la fin du fichier (bricolage, faut pas qu'il y ai des cases vides)int i =1 ;
                            while (oSheet.get_Range("A" + i, "A" + i).Text != "")
                                    {
                                        i++;
                                    }
                        //ecrire dans le fichier                        oSheet.Cells.Cells[i, 1] = dateCommande;
    //fermeture Propre d'excel
     oBook.Save();
                if (oBook != null) { oBook.Close(true, nomfichier, Missing.Value); }
                if (oSheet != null) {System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet); 
                oSheet = null; }
                if (oBook != null) {System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook) ;
                oBook = null; }
                if (oBooks != null) {System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks) ;
                oBooks = null; }
                if (oExcelApp != null) 
                { 
                oExcelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcelApp); oExcelApp = null;

  2. #2
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    Bonjour,

    si tu passes par ici, tu pourrais me donner de la référence à ajouter ?

    Merci,

    Jérôme.
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  3. #3
    Expert éminent
    Avatar de Ditch
    Inscrit en
    Mars 2003
    Messages
    4 160
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mars 2003
    Messages : 4 160
    Points : 9 634
    Points
    9 634
    Par défaut
    Citation Envoyé par Cardi
    Bonjour,

    si tu passes par ici, tu pourrais me donner de la référence à ajouter ?

    Merci,

    Jérôme.
    Excel 12.0 si tu es sur 2007

    Didier Danse

    Most Valuable Profesionnal SharePoint
    Microsoft Certified Application Developer
    Mes articles sur developpez.com
    Mon site perso


  4. #4
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 25
    Points : 22
    Points
    22
    Par défaut name space a ajouter
    voil le name space a ajouter pour travailler sur les fichiers excel :

    Microsoft.Office.Interop.Excel

    et voici le lien pour telecharger les dll de l'office:

    http://support.microsoft.com/kb/897646/fr

    mais par contre est ce qu'il y a kelkin qui sait comment faire pour ouvrir le browser dans c# pour specifier des fichier excel
    et Merci

Discussions similaires

  1. Manipuler Excel via Ole automation
    Par falcon dans le forum Excel
    Réponses: 3
    Dernier message: 02/10/2007, 15h39
  2. [Manipulation Excel] Executer une macro Excel depuis Access
    Par sebastien_oasis dans le forum VBA Access
    Réponses: 2
    Dernier message: 30/05/2007, 15h21
  3. Manipuler Excel
    Par BilTCD dans le forum C#
    Réponses: 1
    Dernier message: 18/01/2007, 16h01
  4. accélerer des manipulations Excel
    Par pschmidtke dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 30/06/2006, 20h02
  5. accélerer des manipulations Excel
    Par pschmidtke dans le forum Access
    Réponses: 5
    Dernier message: 27/06/2006, 15h15

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