Charger un fichier Exel

nissan1 Messages postés 16 Date d'inscription vendredi 7 mai 2010 Statut Membre Dernière intervention 25 juillet 2010 - 7 mai 2010 à 14:29
nissan1 Messages postés 16 Date d'inscription vendredi 7 mai 2010 Statut Membre Dernière intervention 25 juillet 2010 - 10 mai 2010 à 12:19
Bonjour,
s'il vous plait je voudrais savoir comment je peut lire et charger une matrice qui est stocker dans un fichier exel.

6 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
7 mai 2010 à 15:48
Faudra passer par les interfaces COM.
Exemples:
http://www.cppfrance.com/codes/AUTOMATISER-EXCEL-S ANS-MFC-NI-IMPORT_30147.aspx

http://www.cppfrance.com/codes/AUTOMATION-EXCEL-ENTIEREMENT-WIN32-SOUS-FORME-CLASSE_44276.aspx

ciao...
BruNews, MVP VC++
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
7 mai 2010 à 15:50
Les memes liens en plus propre:
http://www.cppfrance.com/code.aspx?ID=30147
http://www.cppfrance.com/code.aspx?ID=44276

ciao...
BruNews, MVP VC++
0
nissan1 Messages postés 16 Date d'inscription vendredi 7 mai 2010 Statut Membre Dernière intervention 25 juillet 2010
8 mai 2010 à 19:03
enfait deja merci beaucoup et je suis un debutant et je programme en C en editeur codeblockes pouvez vous m'aider car j'ai pas bien compris le contenu des liens.
Voila mon code ou maintenant je saisie manuellement les element de la matrice mais quand la taille est grande ce n'est pas evident de faire une saisie manuel.
C'est pour cela je veux faire une lecture d'un fichier exel contenant les elements de la matrice.
/**************************************************************/
/***************** Analyse d'impacts ****************/
/**************************************************************/

#include <stdio.h>
#include <math.h>

#define MAXSIZE 8 // taille des tableaux

/****************************************************/
/************* Prototypes des fonctions *************/
/****************************************************/

void create_matrix(float *, int, int);
void display_matrix(float *, int, int);
int compute(float *, float *, int dim);

/****************************************************/
/************* Fonction Principale **************/
/****************************************************/

int main (int argc, const char * argv[]) {
int dim;
int toto;
float e[MAXSIZE * MAXSIZE];
float c[MAXSIZE];



printf ("\nQuelle est la dimention de la matrice? (Max %d) \t",MAXSIZE);
scanf ("%d",&dim);


printf ("\n le nombre d'iteration est %d\n", compute(e,c,dim));


scanf("%d", &toto);
getchar();
return 0;
}

/****************************************************/
/************* Fonction Secondaires **************/
/****************************************************/


/*******************************************************************/
/****** Fonction pour créer une matrice [taille_1 x taille_2] ******/
/*******************************************************************/

void create_matrix(float *tableau, int taille_1, int taille_2 )
{
int i_t1, i_t2;

for ( i_t1= 0; i_t1 < taille_1; i_t1++)
{

printf ("Line %d:\t",i_t1);
for ( i_t2 = 0; i_t2 < taille_2; i_t2++)
scanf ("%f",&tableau[((i_t1 * taille_1) + i_t2)]);
printf ("\n");
}

}

/*******************************************************************/
/****** Fonction pour afficher une matrice [taille_1 x taille_2] ***/
/*******************************************************************/

void display_matrix(float *tableau, int taille_1, int taille_2 )
{
int i_t1, i_t2;
for (i_t1 = 0; i_t1 < taille_1; i_t1++)
{
for ( i_t2 = 0; i_t2 < taille_2; i_t2++)
printf ("%f\t", tableau[((i_t1 * taille_1) + i_t2)]);
}
printf ("\n");
}


/*******************************************************************/
/***** Fonction pour calculer et rechercher le point d'équilibre ***/
/*******************************************************************/

int compute(float *e, float *c, int dim)
{
int vecteur_egaux;
float r[MAXSIZE];
float a[MAXSIZE];
float b[MAXSIZE];
int i=0;
int j=0;
int nb_iteration;

nb_iteration=0;
vecteur_egaux = 0;

printf ("\n\n\n\t******* CREATION DE LA MATRICE E *******\n");
printf ("\n*******Saisie de la matrice E*******\n\n");
create_matrix(e, dim, dim);

printf ("\n\t******* CREATION DU VECTEUR C *******\n");
printf ("\n*******Saisie de la matrice C*******\n\n");
create_matrix(c, 1, dim);

for (i = 0; i < dim; i++)
{
a[i]=c[i];

}
while (!vecteur_egaux)
{
for (i = 0; i < dim; i++)
{
b[i]=c[i];

}

for (i = 0; i < dim; i++)
{
r[i] = 0;
for (j = 0; j < dim; j++)
{
r[i] += c[j] * e[i + (j * dim)];

}

}
vecteur_egaux = 1;

for (i = 0; i < dim; i++)
{
c[i]=((expf (2 * r[i]) - 1) / (expf (2 * r[i]) + 1))+ a[i];
}
for (i = 0; i < dim; i++)
{
if (c[i] != b[i])
{
vecteur_egaux = 0;
}
}

printf ("\n");
nb_iteration++;

printf ("\n*******VECTEUR C:\n");
display_matrix(c, 1,dim);
printf ("\n*******VECTEUR R:\n");
display_matrix(r, 1,dim);

}
printf ("\n\n\n\t\t*******RESULTAT*******\n\n\n");

return nb_iteration;
}
/****************** The end *********************************/
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
8 mai 2010 à 21:28
Il est clair que faire du COM pour lire dans un Excel, on va attendre un peu.
Le plus simple est d'exporter les données de Excel vers un fichier direct en binaire, tu n'auras plus qu'à aspirer les floats depuis ton prog de test en C.

--------------------
Option Explicit

Function EcrireTabFloats(c As Range, nbr As Long, nomFL As String) As Long
Dim tbl() As Single
Dim i As Long, vRet As Long
If nbr <= 0 Then Exit Function
On Error GoTo ecrirEXIT
ReDim tbl(nbr - 1)
On Error GoTo freeMEM
Open nomFL For Binary Access Write As #1
On Error GoTo flCLOSE
i = 0
fromCELLS:
tbl(i) = CSng(c.Offset(i, 0))
i = i + 1
If i < nbr Then GoTo fromCELLS
Put #1, 1, tbl
vRet = 1
flCLOSE: Close #1
freeMEM:
Erase tbl
ecrirEXIT: EcrireTabFloats = vRet
End Function

Sub FaireTab()
Dim s As String
s = ThisWorkbook.Path & "\flts.dat"
If EcrireTabFloats(Range("A1"), 396, s) = 0 Then
MsgBox "ERR", vbCritical
End If
End Sub
----------------------------

Voila ce que tu colle dans un module (ALT+F11 pour avoir l'editeur VBA) dans ton fichier Excel.
Au besoin, suffit de modifier les params qui sont dans FaireTab(), Range("A1") est la 1ere cellule de la colonne et derriere tu mets le nbr de floats à exporter.

ciao...
BruNews, MVP VC++
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
nissan1 Messages postés 16 Date d'inscription vendredi 7 mai 2010 Statut Membre Dernière intervention 25 juillet 2010
10 mai 2010 à 10:28
Merci beaucoup brunews c'est tres gentil de ta part je vais l'essayer toute suite.
0
nissan1 Messages postés 16 Date d'inscription vendredi 7 mai 2010 Statut Membre Dernière intervention 25 juillet 2010
10 mai 2010 à 12:19
Re Bonjour,
enfait Bruno j'ai:
1-ert un ficher exel ou j'ai mis une matrice 8*8:
0 0 0 0 0 0 0 0
0,3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0,6 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0

2-j'ai copier le code que tu ma envoyer dans un module mais quand j'execute ya rien,et spl tu peut me dire quelle fonction je doit utiliser pour aspiret les floats depuis mon programme de tests.Merci
0
Rejoignez-nous