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

C++Builder Discussion :

Afficher le contenu d'un fichier xls dans un DBgrid [Sources]


Sujet :

C++Builder

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2003
    Messages : 41
    Points : 33
    Points
    33
    Par défaut Afficher le contenu d'un fichier xls dans un DBgrid
    Bonjour,

    J'aimerai afficher le contenu d'un fichier excel (XP) dans un composant DBGrid. Je ne vois pas comment faire... Pouvez-vous m'aider !!!

    Merci

  2. #2
    Membre régulier

    Profil pro
    Inscrit en
    Mars 2002
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 59
    Points : 84
    Points
    84
    Par défaut
    il existe plusieur solution plus ou moins compliquer...

    Dans un premier temps si tu veux conserver la presentation type xl (couleur bordure .... ) sa me parait tres difficile a fair a moins d'utiliser un ocx pour excel ou un lien ole mais la je ne peut pas t'aider.

    Par contre si ce n'est qu'un tableaux de donnee tu peut facilement le sauver en csv. Puis le relire dans un stringGrid (sa ne se fait pas automatiquement) mais il a deja un post sur ce forum ou on explique comment relire un fichier txt dans un stringGrid..

    Si tu le retrouve pas fait moi signe je regarderait si j'ai pas un truc deja fais

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2003
    Messages : 41
    Points : 33
    Points
    33
    Par défaut
    Non malheureusement je n'ai rien trouvé !!! Peux tu regarder si tu as une soluce

    Merci

  4. #4
    Membre régulier

    Profil pro
    Inscrit en
    Mars 2002
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 59
    Points : 84
    Points
    84
    Par défaut
    voila ce que j'avait recuperer il y a quelque temps sir un site qui n'existe plus drdelphi.....

    Saving and loading a StringGrid to file


    --------------------------------------------------------------------------------

    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
     
     
    //---------------------------------------------------------------------------
    // Saving and loading a StringGrid to and from file
    // --------------------------------------------------
    //           (2000) DrDelphi 
    #include 
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::SaveGridToFile(TStringGrid *Grid,AnsiString ofilename)
     
    {  TStringList *list= new TStringList; //create the list to save
     
      for (int rowint=0;rowintRowCount;rowint++)
      {
        for (int colint=0;colintColCount ;colint++)
        {
           list->Add(Grid->Cells[rowint][colint]); //assign the cells string to list
        }
      }
     
     
     list->SaveToFile(ofilename); //save the list to file
     delete list; // free the list from memory
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::LoadGridFromFile(TStringGrid *Grid,AnsiString ofilename)
    {
      TStringList *list=new TStringList;  //create the list to populate
      list->LoadFromFile(ofilename);     //load it from file
     
      /// assign each line to its cell in the grid
      for (int listint=0;listintCount;listint++)
      {
     
        for (int rowint=0;rowintRowCount;rowint++)
        {
          for (int colint=0;colintColCount ;colint++)
          {
             Grid->Cells[rowint][colint]=list->Strings[0];
             list->Delete(0);
          }
        }
     }
     delete list; ///free the list
     }
    //---------------------------------------------------------------------------
     void __fastcall TForm1::FormCreate(TObject *Sender)  //Event handler
    {
     
      //populate the Grid's cells with some data
      for (int rowint=0;rowintRowCount;rowint++)
      {
        for (int colint=0;colintColCount ;colint++)
        {
           StringGrid1->Cells[rowint][colint]=IntToStr(rowint)+"<>"+IntToStr(colint);
        }
      }
     
     // blank a few out to show the save maintains this relationship
     StringGrid1->Cells[0][0]="";
     StringGrid1->Cells[3][3]="";
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender) //Event handler
    {
      //call the Save function
      SaveGridToFile(StringGrid1,"C:\\windows\\desktop\\griddata.txt");
     
      //call the Clear function
        ClearGrid(StringGrid1);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender) //Event handler
    {
     
      //call the Load function
      LoadGridFromFile(StringGrid1,"C:\\windows\\desktop\\griddata.txt");
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ClearGrid(TStringGrid *Grid)
    {
      //iterate through the entire grid, clearing each cell
      for (int rowint=0;rowintRowCount;rowint++)
      {
       for (int colint=0;colintColCount;colint++)
       Grid->Cells[rowint][colint]="";
      }
     
    }

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2003
    Messages : 41
    Points : 33
    Points
    33
    Par défaut
    Lorsque j'essaie il ne reconnait pas les fonctions :SaveGridToFile, LoadGridFromFile, ClearGrid !!!! C'est à moi de les déclarer dans mon .h si c'estle cas je ne sais pas le faire

    Merci de ton aide

  6. #6
    Membre régulier

    Profil pro
    Inscrit en
    Mars 2002
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 59
    Points : 84
    Points
    84
    Par défaut
    en fait a l'origine elle sont propre a une form pour le cas generale tu remplace
    void __fastcall TForm1::LoadGridFromFile(TStringGrid *Grid,AnsiString ofilename)
    par
    void LoadGridFromFile(TStringGrid *Grid,AnsiString ofilename)

Discussions similaires

  1. Comment afficher le contenu d'un fichier ini dans un mémo?
    Par Jayceblaster dans le forum Langage
    Réponses: 7
    Dernier message: 13/05/2014, 17h38
  2. Afficher le contenu d'un fichier TEXT dans une edit
    Par darkman13130 dans le forum C++Builder
    Réponses: 1
    Dernier message: 06/06/2008, 16h41
  3. copie le contenu d'un fichier xls dans un fichier txt
    Par mariafan dans le forum Langage
    Réponses: 22
    Dernier message: 09/08/2007, 14h07
  4. Réponses: 4
    Dernier message: 11/07/2007, 18h40
  5. Réponses: 2
    Dernier message: 20/11/2006, 13h55

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