source: ether_statistics/service/implementation/com/medias/integration/lecture_ecriture/LectureUnites.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 2.4 KB
Line 
1/*
2 * Created on 29 Jan. 2007
3 */
4/**
5 * @author
6 *
7 *
8 */
9package com.medias.integration.lecture_ecriture;
10
11import com.medias.Constantes;
12import jxl.Sheet;
13import jxl.Workbook;
14import jxl.WorkbookSettings;
15import jxl.read.biff.BiffException;
16
17import java.io.File;
18import java.io.IOException;
19import java.util.ArrayList;
20
21public class LectureUnites {
22        public LectureUnites() {
23        }
24
25        public void lireFichier() {
26                String nomFichierUni = Constantes.cheminListes + "/" + Constantes.nomListeUnites;
27                File fichier = new File(nomFichierUni);
28                if (fichier.exists()) {
29                        // Etape ou l' on crée le Workbook
30                        Workbook workbook = null;
31                        try {
32                                WorkbookSettings ws = new WorkbookSettings();
33                                ws.setEncoding(Constantes.encodageDefaut);
34                                workbook = Workbook.getWorkbook(fichier, ws);
35                        } catch (BiffException e) {
36                                e.printStackTrace();
37                        } catch (IOException e) {
38                                e.printStackTrace();
39                        }
40                        // Etape ou l'on récupére les données de la 1ére page du classeur
41                        Sheet sheet = workbook.getSheet(0);
42                        // Etape d'initialisation des listes.
43                        numerosUni = new ArrayList<String>();
44                        codesUni = new ArrayList<String>();
45                        nomsUni = new ArrayList<String>();
46                        typesUni = new ArrayList<String>();
47                       
48                        int nbUnites = sheet.getRows() - 1;//Constantes.nbUnites;
49                        // Etape de lecture des cellules
50                        for (int numUni = 0; numUni < nbUnites; numUni++) {
51                                numerosUni.add(sheet.getCell(0, numUni + 1).getContents());
52                                codesUni.add(sheet.getCell(1, numUni + 1).getContents());
53                                nomsUni.add(sheet.getCell(2, numUni + 1).getContents());
54                                typesUni.add(sheet.getCell(3, numUni + 1).getContents());
55                        }
56                        // Etape de fermeture du flux
57                        workbook.close();
58                }
59        }
60
61        public int getIndice(int numero) {
62                int indice = -1;
63                int numeroCourant;
64                for (int indiceListe = 0; indiceListe < numerosUni.size(); indiceListe++) {
65                        numeroCourant = Integer.parseInt((String)numerosUni.get(indiceListe));
66                        if (numeroCourant == numero) {
67                                indice = indiceListe;
68                                return indice;
69                        }
70                }
71                return indice;
72        }
73
74        public ArrayList<String> getCodesUni() {
75                return codesUni;
76        }
77
78        public ArrayList<String> getNumerosUni() {
79                return numerosUni;
80        }
81
82        public ArrayList<String> getNomsUni() {
83                return nomsUni;
84        }
85
86        public ArrayList<String> getTypesUni() {
87                return typesUni;
88        }
89
90        private ArrayList<String> numerosUni;
91        private ArrayList<String> codesUni;
92        private ArrayList<String> nomsUni;
93        private ArrayList<String> typesUni;
94}
Note: See TracBrowser for help on using the repository browser.