/* * Created on 29 Jan. 2007 */ /** * @author * * */ package com.medias.integration.lecture_ecriture; import com.medias.Constantes; import jxl.Sheet; import jxl.Workbook; import jxl.WorkbookSettings; import jxl.read.biff.BiffException; import java.io.File; import java.io.IOException; import java.util.ArrayList; public class LectureCapteurs { public LectureCapteurs() { } public void lireFichier() { String nomFichierCapt = Constantes.cheminListes + "/" + Constantes.nomListeCapteurs; File fichier = new File(nomFichierCapt); if (fichier.exists()) { // Etape ou l' on crée le Workbook Workbook workbook = null; try { WorkbookSettings ws = new WorkbookSettings(); ws.setEncoding(Constantes.encodageDefaut); workbook = Workbook.getWorkbook(fichier, ws); } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Etape ou l'on récupére les données de la 1ére page du classeur Sheet sheet = workbook.getSheet(0); // Etape d'initialisation des listes. numerosCapt = new ArrayList(); typesCapt = new ArrayList(); fabriquantsCapt = new ArrayList(); modelesCapt = new ArrayList(); numsSeriesCapt = new ArrayList(); etalonnagesCapt = new ArrayList(); nomsCaptFromFile = new ArrayList(); // descriptionsCapt = new ArrayList(); // descriptionsTypeCapt = new ArrayList(); numsParametresCapt = new ArrayList>(); int nbCapteurs = sheet.getRows() - 1;//Constantes.nbCapteurs; String numsParametres, numParametre, paramDer; int paramCourant; ArrayList numsParametresLigne; // Etape de lecture des cellules for (int numCapt = 0; numCapt < nbCapteurs; numCapt++) { numerosCapt.add(sheet.getCell(0, numCapt + 1).getContents()); typesCapt.add(sheet.getCell(1, numCapt + 1).getContents()); fabriquantsCapt.add(sheet.getCell(2, numCapt + 1).getContents()); modelesCapt.add(sheet.getCell(3, numCapt + 1).getContents()); numsSeriesCapt.add(sheet.getCell(4, numCapt + 1).getContents()); etalonnagesCapt.add(sheet.getCell(5, numCapt + 1).getContents()); //descriptionsCapt.add(sheet.getCell(4, numCapt + 1).getContents()); //descriptionsTypeCapt.add(sheet.getCell(6, numCapt + 1).getContents()); numsParametres = sheet.getCell(6, numCapt + 1).getContents(); numsParametresLigne = new ArrayList(); while (numsParametres.indexOf(Constantes.delimiteurXLS) != -1) { // On récupére la 1ére donnée de la mesure avant le délimiteur numParametre = numsParametres.substring(0, numsParametres.indexOf(Constantes.delimiteurXLS)).trim(); // On récupére la mesure restante aprés le délimiteur numsParametres = numsParametres.substring(numsParametres.indexOf(Constantes.delimiteurXLS)+1).trim(); if (numParametre.equals("..")) { if (numsParametres.indexOf(Constantes.delimiteurXLS) != -1) paramDer = numsParametres.substring(0, numsParametres.indexOf(Constantes.delimiteurXLS)).trim(); else paramDer = numsParametres.trim(); paramCourant = Integer.parseInt(numsParametresLigne.get(numsParametresLigne.size()-1)); while (paramCourant < Integer.parseInt(paramDer)-1) { paramCourant++; numsParametresLigne.add(String.valueOf(paramCourant)); } } else { numsParametresLigne.add(numParametre); } } numParametre = numsParametres; numsParametresLigne.add(numParametre); numsParametresCapt.add(numsParametresLigne); nomsCaptFromFile.add(sheet.getCell(7, numCapt + 1).getContents()); } // Etape de fermeture du flux workbook.close(); } } public int getIndice(int numero) { int indice = -1; int numeroCourant; for (int indiceListe = 0; indiceListe < numerosCapt.size(); indiceListe++) { numeroCourant = Integer.parseInt((String)numerosCapt.get(indiceListe)); if (numeroCourant == numero) { indice = indiceListe; return indice; } } return indice; } public ArrayList getNumerosCapt() { return numerosCapt; } public ArrayList getDescriptionsCapt() { return descriptionsCapt; } public ArrayList getEtalonnagesCapt() { return etalonnagesCapt; } public ArrayList getFabriquantsCapt() { return fabriquantsCapt; } public ArrayList getModelesCapt() { return modelesCapt; } public ArrayList getNumsSeriesCapt() { return numsSeriesCapt; } public ArrayList> getNumsParametresCapt() { return numsParametresCapt; } public ArrayList getTypesCapt() { return typesCapt; } public ArrayList getDescriptionsTypeCapt() { return descriptionsTypeCapt; } public ArrayList getNomsCaptFromFile() { return nomsCaptFromFile; } private ArrayList numerosCapt; private ArrayList typesCapt; private ArrayList fabriquantsCapt; private ArrayList modelesCapt; private ArrayList numsSeriesCapt; private ArrayList etalonnagesCapt; private ArrayList> numsParametresCapt; private ArrayList nomsCaptFromFile; private ArrayList descriptionsCapt; private ArrayList descriptionsTypeCapt; }