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

Interfaces Graphiques en Java Discussion :

Lire des données a partir d'un fichier Excel


Sujet :

Interfaces Graphiques en Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 10
    Points : 8
    Points
    8
    Par défaut Lire des données a partir d'un fichier Excel
    Bonjour tout le monde,

    je cherche a lire des données d'un fichier Excel sous java et je ne sais pas comment faire

    Voilà mon programme :
    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
    package crb;
     
    import java.awt.Color;
    import java.awt.Graphics;
     
    import javax.swing.JPanel;
     
    public class panneau extends JPanel{
    /**
         * 
         */
        int points [], nbre;
         int pointsa [], nbrea;
         final int hauteur = 100;
         int offsetX = 0;
         int offsetY = 0;
        private static final long serialVersionUID = 1L;
     
     
    public void paintComponent(Graphics g)
    {
         int h = this.getHeight();
         int w = this.getWidth();
     
         g.setColor(Color.pink);
         g.fillRect(0, 0, w, h);
     
         int roundOffsetX = (int) Math.round(this.offsetX);
         int roundOffsetY = (int) Math.round(this.offsetY);
     
         g.setColor(Color.red);
         g.drawLine(w / 3 + roundOffsetX, 0, w / 3 + roundOffsetX, h);
         g.drawLine(0, 4*h/5  + roundOffsetY, w, 4*h/5  + roundOffsetY);    
     
     
        g.setColor(Color.black);
        nbre=26;
           int points[] =new int[nbre];
           points[0]=0;
           points[1]=0;
           points[2]=40;
           points[3]=40;
           points[4]=80;
           points[5]=80;
           points[6]=120;
           points[7]=120;
           points[8]=160;
           points[9]=160;
           points[10]=200;
           points[11]=200;
           points[12]=240;
           points[13]=240;
           points[14]=280;
           points[15]=280;
           points[16]=320;
           points[17]=320;
           points[18]=360;
           points[19]=360;
           points[20]=400;
           points[21]=400;
           points[22]=440;
           points[23]=440;
           points[24]=480;
           points[25]=480;
     
           int pointsa[] =new int[nbre];
     
           pointsa[0]=-420;
           pointsa[1]=-410;
           pointsa[2]=-405;
           pointsa[3]=-400;
           pointsa[4]=-390;
           pointsa[5]=-385;
           pointsa[6]=-380;
           pointsa[7]=-360;
           pointsa[8]=-340;
           pointsa[9]=-320;
           pointsa[10]=-300;
           pointsa[11]=-280;
           pointsa[12]=-260;
           pointsa[13]=-240;
           pointsa[14]=-220;
           pointsa[15]=-200;
           pointsa[16]=-180;
           pointsa[17]=-160;
           pointsa[18]=-140;
           pointsa[19]=-120;
           pointsa[20]=-100;
           pointsa[21]=-80;
           pointsa[22]=-60;
           pointsa[23]=-40;
           pointsa[24]=-20;
           pointsa[25]=00;
     
        // Barre.   
        int i,j;
        j=0;
        i=0;
        while ((i <nbre-1)&&(j<nbre-1)) {
     
          g.drawLine(points[i]+w / 3, pointsa[j]+4*h/5, 
                  points[i+1]+w / 3, pointsa[j+1]+4*h/5);
     
          i=i+1;
          j=j+1;
        }
        g.setColor(Color.blue);
        int a,b;
        a=0;
        b=0;
        int posX=1,posY=-1;
        while ((a <nbre-1)&&(b<nbre-1)) {
            for(posX=1;posX<20;posX++)
                for(posY=-1;posY>-30;posY--)
            g.drawLine(points[a]+w / 3, pointsa[b]+4*h/5+posY, 
                    points[a+1]+w / 3, pointsa[b+1]+4*h/5+posY);
     
            a=a+1;
            b=b+1;
            posX++;
            posY--;
            //this.repaint();
          }
       [COLOR=#0000CD] g.drawString("",10,20);
    }
     
    }
    Je veux qu'au lieu de remplir les tableaux points et point, stocker leurs données dans un tableau Excel et après l'utiliser. Est ce que vous pouvez m'aider ?

    Merci d'avance.

  2. #2
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 310
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 310
    Points : 9 522
    Points
    9 522
    Billets dans le blog
    1
    Par défaut
    Regarde du côté de POI
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 10
    Points : 8
    Points
    8
    Par défaut
    Bonjour
    merci bien pour votre réponse

    j'ai deja telecharger POI et j'voulu lire les données d'un fichier Excel

    et voila 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
    import java.io.FileInputStream;
    import java.io.IOException;
    
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
     
    public class exel 
    {
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
           
            XSSFWorkbook excel;
            XSSFSheet st;
            XSSFCell poNum;
            XSSFRow row;
             
            excel = new XSSFWorkbook(new FileInputStream("C:/chau/cll.xlsx"));
    
            st = excel.getSheet("donnees");
             
            row = st.getRow(4);
            poNum = row.getCell(4);
             
            String string = poNum.getStringCellValue();
            System.out.println(string);
            
            
            
            
        }
    }
    
    mais j'ai cette erreur:
    Exception in thread "main" java.lang.NullPointerException
    at exel.main(exel.java:27)



    la ligne 27 correspond à : row = st.getRow(4);

    et voila aussi le fichier Excel

    merci d'avance
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Lire des données outlook à partir d'excel
    Par GENI36 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 02/10/2008, 16h18
  2. Lire des données outlook à partir d'excel
    Par GENI36 dans le forum Outlook
    Réponses: 3
    Dernier message: 16/09/2008, 11h10
  3. Lire des données a partir d'un fichier txt
    Par walido dans le forum C#
    Réponses: 13
    Dernier message: 30/05/2007, 13h22
  4. Réponses: 2
    Dernier message: 29/01/2007, 14h14
  5. Réponses: 3
    Dernier message: 09/09/2006, 13h24

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