source: ether_megapoli/trunk/service/implementation/com/medias/integration/lecture_ecriture/LectureUnites.java @ 482

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

BO insertion données _ insertion code medias package insertion

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