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
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
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
Non malheureusement je n'ai rien trouvé !!! Peux tu regarder si tu as une soluce
Merci
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]=""; } }
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
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)
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager