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 :

composant TExcel dans c++ builder


Sujet :

C++Builder

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    F�vrier 2005
    Messages
    11
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 11
    Par d�faut composant TExcel dans c++ builder
    bonjour � tous je suis � la recherche de documentation sur les composants Texcel de builder 6 quelqu'un
    pourrait il m'aider � charger un fichier excel avec ce composant ?

  2. #2
    Membre �prouv�
    Avatar de Freeze
    Homme Profil pro
    Inscrit en
    Octobre 2002
    Messages
    131
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (�le de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 131
    Par d�faut
    tu peux utiliser cette classe :

    le fichier .cpp :

    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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
     
    //---------------------------------------------------------------------------
    #include "Excel.h"
    //---------------------------------------------------------------------------
    TExcel::TExcel(AnsiString nom)
    {
       FDejaOpen = true;
       FOleExcel.Clear();
       FWorkbook.Clear();
       FWorksheet.Clear();
       Connect();
       OpenBook(nom);
    }
    //---------------------------------------------------------------------------
    TExcel::~TExcel()
    {
       SaveBook();
       CloseBook();
       Deconnect();
    }
    //---------------------------------------------------------------------------
    void TExcel::Connect(void)
    {
       if (FOleExcel.IsEmpty())
       {
          FDejaOpen = true;
          try
          {  FOleExcel = Variant::GetActiveObject("Excel.Application");   }
          catch(...)
          {  FOleExcel = Variant::CreateObject("Excel.Application"); FDejaOpen=false;      }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::Deconnect(void)
    {
       if (!FOleExcel.IsEmpty())
       {
          CloseBook();
          if (!FDejaOpen)
             FOleExcel.OleFunction("Quit");
          FOleExcel.Clear();
          FWorkbook.Clear();
          FWorksheet.Clear();
       }
    }
    //---------------------------------------------------------------------------
    bool TExcel::OpenBook(AnsiString nom)
    {
       bool ret=false;
       Variant name,workbooks;
     
       name=nom;   name.ChangeType(varOleStr);
       try
       {
          workbooks = FOleExcel.OlePropertyGet("Workbooks");
          FWorkbook = workbooks.OleFunction("Open",name);
       }
       catch(...)
       {  FWorkbook.Clear();   }
       if (!FWorkbook.IsEmpty())      ret=true;
       return(ret);
    }
    //---------------------------------------------------------------------------
    void TExcel::CloseBook(void)
    {
       Variant savechange;
       savechange=false;
       if (!FWorkbook.IsEmpty())
       {
          try   {  FWorkbook.OleFunction("Close",savechange);   }
          catch(...)         {  }
       }
       FWorkbook.Clear();
       FWorksheet.Clear();
    }
    //---------------------------------------------------------------------------
    void TExcel::SaveBook(void)
    {
       if (!FWorkbook.IsEmpty())
       {
          try   {  FWorkbook.OleProcedure("Save");  }
          catch(...)  {  }
       }
    }
    //---------------------------------------------------------------------------
    int TExcel::CountSheet(void)
    {
       int nb=0;
       Variant worksheets;
       if (!FWorkbook.IsEmpty())
       {
          try
          {
             worksheets=FWorkbook.OlePropertyGet("Worksheets");
             nb = worksheets.OlePropertyGet("Count");
          }
          catch(...)  {  }
       }
       return(nb);
    }
    //---------------------------------------------------------------------------
    AnsiString TExcel::SelectSheet(int sheet)
    {
       AnsiString n="";
       if (!FWorkbook.IsEmpty())
       {
          try
          {
             FWorksheet = FWorkbook.OlePropertyGet("Worksheets",sheet);
             FWorksheet.OleProcedure("Activate");
             n = FWorksheet.OlePropertyGet("Name");
          }
          catch(...)  {  }
       }
       return(n);
    }
    //---------------------------------------------------------------------------
    bool TExcel::GetCell(int lig,int col,Variant &value)
    {
       bool ret=false;
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell=FWorksheet.OlePropertyGet("Cells",lig,col);
             value=cell.OlePropertyGet("Value");
             ret=true;
          }
          catch(...)
          {  value.Clear(); }
       }
       return(ret);
    }
    //---------------------------------------------------------------------------
    void TExcel::SetCell(int lig,int col,Variant value)
    {
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell = FWorksheet.OlePropertyGet("Cells",lig,col);
             value.ChangeType(varOleStr);
             cell.OlePropertySet("Value",value);
          }
          catch(...)  {  }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::GetMaxRowCol(int &lig,int &col)
    {
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell = FWorksheet.OlePropertyGet("Cells").OleFunction("SpecialCells",11);
             lig = cell.OlePropertyGet("Row");
             col = cell.OlePropertyGet("Column");
          }
          catch(...)  {  lig=0;   col=0;   }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::PrintSheet(void)
    {
       if (!FWorksheet.IsEmpty())
       {
          try
          {  FWorksheet.OleProcedure("PrintOut"); }
          catch(...)  { }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::SetBorder(int lig,int col,bool visible)
    {
       Variant border,cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell=FWorksheet.OlePropertyGet("Cells",lig,col);
             border=cell.OlePropertyGet("Borders");
             if (visible)
                border.OlePropertySet("Weight",-4138);
             else
                border.OlePropertySet("Weight",0);
     
          }
          catch(...)
          {   }
       }
    }
    //---------------------------------------------------------------------------
    le fichier .h

    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
     
    //---------------------------------------------------------------------------
    #ifndef ExcelH
    #define ExcelH
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    //---------------------------------------------------------------------------
    class TExcel
    {
       private:
          void Connect(void);
          void Deconnect(void);
          bool OpenBook(AnsiString nom);
          void CloseBook(void);
          void SaveBook(void);
     
          bool FDejaOpen;
          Variant FOleExcel;
          Variant FWorkbook;
          Variant FWorksheet;
       public:
          TExcel(AnsiString nom);
          ~TExcel();
     
          int CountSheet(void);
          void PrintSheet(void);
          void SetBorder(int lig,int col,bool visible);
          AnsiString SelectSheet(int sheet);
          bool GetCell(int lig,int col,Variant &value);
          void SetCell(int lig,int col,Variant value);
          void GetMaxRowCol(int &lig,int &col);
    };
    //---------------------------------------------------------------------------
    #endif

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    F�vrier 2005
    Messages
    11
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 11
    Par d�faut Texcel
    merci pour l'info mais j'ai d�j� essayer avec ce genre de code

    cela fonctionne mais pas pour ce que je veux faire

    j'aimerais ouvrir un fichier excel, le modifier etc... et quand je quitte excel j'aimerais avoir de nouveau la main dans mon programme pour pouvoir sauver le fichier excel avec un code particulier

    je pensais donc utiliser Texcel, Tworksheet TWorkbook qui ont eux des �v�nement qui se produisent quand on quitte Excel

    mais je n'arrive pas � charger de fichier Excel avec ces composants et je recherche donc des informations � ce sujet car je n'ai pas d'aide d'installer dans c++ builder sur ces composants

    voil� mon probl�me






    Citation Envoy� par Freeze
    tu peux utiliser cette classe :

    le fichier .cpp :

    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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
     
    //---------------------------------------------------------------------------
    #include "Excel.h"
    //---------------------------------------------------------------------------
    TExcel::TExcel(AnsiString nom)
    {
       FDejaOpen = true;
       FOleExcel.Clear();
       FWorkbook.Clear();
       FWorksheet.Clear();
       Connect();
       OpenBook(nom);
    }
    //---------------------------------------------------------------------------
    TExcel::~TExcel()
    {
       SaveBook();
       CloseBook();
       Deconnect();
    }
    //---------------------------------------------------------------------------
    void TExcel::Connect(void)
    {
       if (FOleExcel.IsEmpty())
       {
          FDejaOpen = true;
          try
          {  FOleExcel = Variant::GetActiveObject("Excel.Application");   }
          catch(...)
          {  FOleExcel = Variant::CreateObject("Excel.Application"); FDejaOpen=false;      }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::Deconnect(void)
    {
       if (!FOleExcel.IsEmpty())
       {
          CloseBook();
          if (!FDejaOpen)
             FOleExcel.OleFunction("Quit");
          FOleExcel.Clear();
          FWorkbook.Clear();
          FWorksheet.Clear();
       }
    }
    //---------------------------------------------------------------------------
    bool TExcel::OpenBook(AnsiString nom)
    {
       bool ret=false;
       Variant name,workbooks;
     
       name=nom;   name.ChangeType(varOleStr);
       try
       {
          workbooks = FOleExcel.OlePropertyGet("Workbooks");
          FWorkbook = workbooks.OleFunction("Open",name);
       }
       catch(...)
       {  FWorkbook.Clear();   }
       if (!FWorkbook.IsEmpty())      ret=true;
       return(ret);
    }
    //---------------------------------------------------------------------------
    void TExcel::CloseBook(void)
    {
       Variant savechange;
       savechange=false;
       if (!FWorkbook.IsEmpty())
       {
          try   {  FWorkbook.OleFunction("Close",savechange);   }
          catch(...)         {  }
       }
       FWorkbook.Clear();
       FWorksheet.Clear();
    }
    //---------------------------------------------------------------------------
    void TExcel::SaveBook(void)
    {
       if (!FWorkbook.IsEmpty())
       {
          try   {  FWorkbook.OleProcedure("Save");  }
          catch(...)  {  }
       }
    }
    //---------------------------------------------------------------------------
    int TExcel::CountSheet(void)
    {
       int nb=0;
       Variant worksheets;
       if (!FWorkbook.IsEmpty())
       {
          try
          {
             worksheets=FWorkbook.OlePropertyGet("Worksheets");
             nb = worksheets.OlePropertyGet("Count");
          }
          catch(...)  {  }
       }
       return(nb);
    }
    //---------------------------------------------------------------------------
    AnsiString TExcel::SelectSheet(int sheet)
    {
       AnsiString n="";
       if (!FWorkbook.IsEmpty())
       {
          try
          {
             FWorksheet = FWorkbook.OlePropertyGet("Worksheets",sheet);
             FWorksheet.OleProcedure("Activate");
             n = FWorksheet.OlePropertyGet("Name");
          }
          catch(...)  {  }
       }
       return(n);
    }
    //---------------------------------------------------------------------------
    bool TExcel::GetCell(int lig,int col,Variant &value)
    {
       bool ret=false;
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell=FWorksheet.OlePropertyGet("Cells",lig,col);
             value=cell.OlePropertyGet("Value");
             ret=true;
          }
          catch(...)
          {  value.Clear(); }
       }
       return(ret);
    }
    //---------------------------------------------------------------------------
    void TExcel::SetCell(int lig,int col,Variant value)
    {
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell = FWorksheet.OlePropertyGet("Cells",lig,col);
             value.ChangeType(varOleStr);
             cell.OlePropertySet("Value",value);
          }
          catch(...)  {  }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::GetMaxRowCol(int &lig,int &col)
    {
       Variant cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell = FWorksheet.OlePropertyGet("Cells").OleFunction("SpecialCells",11);
             lig = cell.OlePropertyGet("Row");
             col = cell.OlePropertyGet("Column");
          }
          catch(...)  {  lig=0;   col=0;   }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::PrintSheet(void)
    {
       if (!FWorksheet.IsEmpty())
       {
          try
          {  FWorksheet.OleProcedure("PrintOut"); }
          catch(...)  { }
       }
    }
    //---------------------------------------------------------------------------
    void TExcel::SetBorder(int lig,int col,bool visible)
    {
       Variant border,cell;
       if (!FWorksheet.IsEmpty())
       {
          try
          {
             cell=FWorksheet.OlePropertyGet("Cells",lig,col);
             border=cell.OlePropertyGet("Borders");
             if (visible)
                border.OlePropertySet("Weight",-4138);
             else
                border.OlePropertySet("Weight",0);
     
          }
          catch(...)
          {   }
       }
    }
    //---------------------------------------------------------------------------
    le fichier .h

    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
     
    //---------------------------------------------------------------------------
    #ifndef ExcelH
    #define ExcelH
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    //---------------------------------------------------------------------------
    class TExcel
    {
       private:
          void Connect(void);
          void Deconnect(void);
          bool OpenBook(AnsiString nom);
          void CloseBook(void);
          void SaveBook(void);
     
          bool FDejaOpen;
          Variant FOleExcel;
          Variant FWorkbook;
          Variant FWorksheet;
       public:
          TExcel(AnsiString nom);
          ~TExcel();
     
          int CountSheet(void);
          void PrintSheet(void);
          void SetBorder(int lig,int col,bool visible);
          AnsiString SelectSheet(int sheet);
          bool GetCell(int lig,int col,Variant &value);
          void SetCell(int lig,int col,Variant value);
          void GetMaxRowCol(int &lig,int &col);
    };
    //---------------------------------------------------------------------------
    #endif

  4. #4
    Membre �prouv�
    Avatar de Freeze
    Homme Profil pro
    Inscrit en
    Octobre 2002
    Messages
    131
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (�le de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 131
    Par d�faut
    je vois pas trop ce qui te manque dans ce genre de code ... quant aux composants fournit avec Borland C++ Builder, je te confirme qu'il n'y a pas de documentation, quant � leur fiabilit�, j'en mettrai pas ma main � couper ( j'ai moi m�me pu v�rifier le bordel que ca g�n�re avec diff�rentes versions de Office )... je pr�f�re largement le OLE ...

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    F�vrier 2005
    Messages
    11
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 11
    Par d�faut Texcel
    merci pour l'info

    si on utilise Ole, j'arrive � ouvrir un fichier excel � le visualiser dans Excel

    mais quand je quitte j'aimerai qu excel ne me demande pas de confirmation pour la sauvegarde du fichier que j'ai modifier

    je sauve en fait un fichier au format csv et excel me pose trois ou quatre question pour pouvoir faire sa sauvegarde et c'est tr�s ennnuyeux

    j'aimerais qu'il sauve le fichier sans demander de confirmation

    mais si je mets displayAlerts � false Excel ne sauve plus rien !!!

  6. #6
    Membre �prouv�
    Avatar de Freeze
    Homme Profil pro
    Inscrit en
    Octobre 2002
    Messages
    131
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (�le de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 131
    Par d�faut
    je crois comprendre ce que tu veux ... je te conseille de te pencher sur les macros en VBA ... c'est la meilleure m�thode � mon avis ...

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    F�vrier 2005
    Messages
    11
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 11
    Par d�faut Texcel
    faire une macro de sauvegarde en vba qui enl�verait displayAllerts quand je quitte Excel c'est faisable mais c'est trop compliqu� d' installer la macro de mani�re automatique sur les postes o� se trouve mon programme et puis comment installer une macro de mani�re automatique ???

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    F�vrier 2005
    Messages
    11
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 11
    Par d�faut Texcel
    jai r�solu le probl�me en utilisant un olecontainer et en sauvant moi-m�me le fichier Excel sous le format CSV
    seul petit soucis , c'est un peu plus lent pour l'ouverture et la fermeture du fichier Excel
    Si quelqu'un a une id�e pour acc�lerer cela, elle sera la bienvenue
    merci

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Utilisation de 'vieilles' libraires dans C Builder 6
    Par Gore dans le forum C++Builder
    R�ponses: 7
    Dernier message: 14/10/2004, 21h31
  2. Probleme de composant inclus dans un autre.
    Par viro dans le forum C++Builder
    R�ponses: 7
    Dernier message: 05/04/2004, 15h44
  3. [RAVE]Composant RTF dans une feuille RAVE ?
    Par hpalpha dans le forum Rave
    R�ponses: 3
    Dernier message: 29/03/2004, 19h25
  4. VCL de Crystal Report pour utilisation dans C++Builder
    Par dibak dans le forum C++Builder
    R�ponses: 4
    Dernier message: 16/02/2004, 17h04
  5. Documentation DirectX dans C++Builder 3
    Par srvremi dans le forum DirectX
    R�ponses: 1
    Dernier message: 26/04/2002, 09h59

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