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

Documents Java Discussion :

Lire un fichier Excel


Sujet :

Documents Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut Lire un fichier Excel
    J'ai besoin de lire un fichier Excel. J'ai écrit ce code mais il y a une erreur.

    Voici mon code:

    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
    package javaapplication7;
    import java.io.File;
    import java.io.IOException;
    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    import jxl.read.biff.BiffException;
    import jxl.write.*;
    import jxl.write.Number;
    import java.awt.*;
    import javax.swing.*;
     
    /**
     *
     * @author AGORA
     */
    public class JavaApplication7 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws Exception {
     
     
     
           File f=new File("C:\\Users\\AGORA\\Desktop\\baAse2G.xls");
            Workbook wb=Workbook.getWorkbook(f);
     
            Sheet s=wb.getSheet(0);
           int row =s.getRows();
            int col =s.getColumns();
           for (int i = 0;  i<=row;i++){
              for (int j = 0;  j<=col;j++){ 
                 Cell c=s.getCell(i, j);
     
                 System.out.print(c.getContents()+"\t\t");
              }
                 System.out.print("");
     
           }
             }
    }
    Quelles sont les causes de l'erreur?
    Merci d'avance

  2. #2
    Membre régulier
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2018
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2018
    Messages : 80
    Points : 119
    Points
    119
    Par défaut
    Bonjour,

    Quelle erreur avez-vous ?
    Pour lire simplement un fichier Excel, regardez du côté de POI Apache.

    Bon courage

  3. #3
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    run:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    SYSTEM		GSM		GSM		GSM		GSM		GSM		GSM		GSM		GSM		GSM		DCS		SITE		AGILETE_GSM		AGILETE_GSM		AGILETE_GSM		AITHA		AITHA		AITHA		BOUHLEL_AUT_GSM		BOUHLEL_AUT_GSM		BOUHLEL_AUT_GSM		BOUHLEL_DCS		LAT		35.418354		35.418354		35.418354		35.27402		35.27402		35.27402		35.43264		35.43264		35.43264		35.407115		LON		10.341609		10.341609		10.341609		10.653603		10.653603		10.653603		10.6608		10.6608		10.6608		10.670687		CELL		33AGIGA		33AGIGB		33AGIGC		33AITGA		33AITGB		33AITGC		33BHAGA		33BHAGB		33BHAGC		33BHLDA		CH		10		1		15		12		2		18		17		2		16		527		BSIC		54		77		44		13		14		12		43		77		15		45		CID		33371		33372		33373		33831		33832		33833		33621		33622		33623		33124		LAC		132		132		132		132		132		132		132		132		132		132		DIR		90		230		340		0		170		260		150		240		330		150			at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:318)
    	at javaapplication7.JavaApplication7.main(JavaApplication7.java:39)
    C:\Users\AGORA\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
    BUILD FAILED (total time: 1 second)
    voici l’erreur le ficher excel non lu complet
    je veux utilise bibliothèque jxl.jar pour lire le ficher excel

  4. #4
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,

    remplace ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     for (int i = 0;  i<=row;i++){
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     for (int i = 0;  i< row;i++){
    car il te dit que tu veux afficher plus d´elements que ce qui est contenu dans ton Array.

    Eric

  5. #5
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    bonjour
    c'est reste le même problème

  6. #6
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    le mesage dit qu´il ya erreur a la ligne 39
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    javaapplication7.JavaApplication7.main(JavaApplication7.java:39)
    peux tu nous montrer cette ligne.

    Eric

  7. #7
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Cell c=s.getCell( i,j );

  8. #8
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    remplce ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for (int j = 0;  j<=col;j++){
    par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for (int j = 0;  j< col;j++){
    Eric

  9. #9
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    oui je fais sa mais reste le même problème
    voici le code
    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
    package javaapplication7;
    import java.io.File;
    import java.io.IOException;
    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    import jxl.read.biff.BiffException;
    import jxl.write.*;
    import jxl.write.Number;
    import java.awt.*;
    import javax.swing.*;
     
    /**
     *
     * @author AGORA
     */
    public class JavaApplication7 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws Exception {
     
     
     
           File f=new File("C:\\Users\\AGORA\\Desktop\\baAse2G.xls");
            Workbook wb=Workbook.getWorkbook(f);
     
            Sheet s=wb.getSheet(0);
           int row =s.getRows();
            int col =s.getColumns();
             for (int i = 0;  i<row ;i++){
              for (int j = 0;  j<col ;j++){ 
                 Cell c=s.getCell( i,j );
     
                 System.out.print(c.getContents()+"\t\t");
              }
     
     
              System.out.print("");
             }
     
             }
    }

  10. #10
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    peux tu me donner le contenu du ficheir a lire?

    Eric

  11. #11
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11

  12. #12
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    remplaces ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for (int i = 0;  i<row ;i++){
              for (int j = 0;  j<col ;j++){
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for (int i = 0;  i<col ;i++){
              for (int j = 0;  j<row ;j++){
    Eric

  13. #13
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    Merci beaucoup pour votre aide
    les contenus de ficher sont affiche sur une même ligne et puisque le ficher est long non lu complète
    pouvez -vous m'aider comment les afficher exactement comme le forme d'un excel

  14. #14
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,

    Il faudra créer une liste et ainsi mettre le contenu du fichier et à la fin faire une itération sur cette liste.

    Eric

  15. #15
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    je n'ai pas compris grand chose
    liste de quoi que je vais créer

  16. #16
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    formattes ton code comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    int totalNoOfRows = s.getRows();
    		int totalNoOfCols = s.getColumns();
     
     
    		for (int row = 0; row < totalNoOfRows; row++) {
     
    			for (int col = 0; col < totalNoOfCols; col++) {
    				String format = "%-20s";
    				System.out.format(format, s.getCell(col, row).getContents());
    			}
    			System.out.println();
    		}
    Eric

  17. #17
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2019
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2019
    Messages : 30
    Points : 11
    Points
    11
    Par défaut
    bonjour
    merci beaucoup pour votre aide

Discussions similaires

  1. [Excel] Comment lire des fichiers excel avec php?
    Par dear_rihab dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 02/11/2007, 12h38
  2. [VB6]Lire un fichier excel
    Par LEYLA dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 04/05/2006, 10h04
  3. [CSV] Ecrire et Lire un fichier Excel depuis PHP
    Par cocaetjusdorange dans le forum Langage
    Réponses: 7
    Dernier message: 08/02/2006, 11h10
  4. [C#] Comment lire un fichier Excel ?
    Par lemmings dans le forum ASP.NET
    Réponses: 12
    Dernier message: 23/12/2005, 11h01
  5. lire un fichier excel xls et l'exporter dans une db Mysql
    Par etarip dans le forum Administration
    Réponses: 4
    Dernier message: 10/10/2005, 16h02

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