Probléme de boucles

Raoul007 - 30 août 2012 à 10:14
 Utilisateur anonyme - 2 sept. 2012 à 17:24
Bonjour à la communauté, j'ai un problème qui me pertube depuis fort bien longtemps et c'est la raison pour laquelle je me penche vers vous bref mon problème se situe au niveau de la lecture d'un fichier excell, la lecture se passe bien , je peux faire des conditions pour prendre certaines lignes et mettre en base mais le problème est que je dois lire tout le fichier et lors de ma recherche si je rencontre une chaine de caractères, je lis la suite des lignes(chiffres) pour envoyer en base jusqu'à rencontrer une prochaine chaine de caractères. J'ai déjà essayé toutes sortes de boucles donc si vous pouvez m'aider j'en serais ravi. Merci d'avance à vous et voici le code !!!


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lecturefichier;

/**
*
* @author RICKYSTAR 007
*/

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class LectureFichier1 {

private String recupa;
private String recupb;
private String recupc;
private String recupd;
private String recupe;
private String recupf;
private String recupg;
private String recuph;
private String recupi;
private String recupj;
private String recupk;
private String recupl;
private String recupm;
private String recupn;
private String recupo;
private String recupp;
private String recupq;
private String recupr;
private String recups;
private String recupt;
private String recupu;
private String recupv;
private String recupw;
private String recupx;
private String recupy;
private String recupz;
private String recupaa;
private String recupab;
private String recupac;
private String recupad;
private String recupae;
private String recupaf;
private String recupag;
private String recupah;
private String recupai;
private String recupaj;
private String recupak;
private String recupal;
private String recupam;
private String recupan;
private String recupao;
private String recupap;
private String recupaq;
private String recupar;
private String recupas;
private String recupat;
private String recupau;
private String recupav;
private String recupaw;


private String tableau[];


public LectureFichier1() throws ClassNotFoundException, BiffException{
try
{

Workbook workbook=Workbook.getWorkbook(new File("C:\\Users\\RICKYSTAR 007\\Documents\\Memoire stage\\FichierExcell.xls"));

Sheet sheet= workbook.getSheet(0);

Cell a1=sheet.getCell("A2");
Cell b1=sheet.getCell("B2");
Cell c1=sheet.getCell("C2");
Cell d1=sheet.getCell("D2");
Cell e1=sheet.getCell("E2");
Cell f1=sheet.getCell("F2");
Cell g1=sheet.getCell("G2");
Cell h1=sheet.getCell("H2");
Cell i1=sheet.getCell("I2");
Cell j1=sheet.getCell("J2");
Cell k1=sheet.getCell("K2");
Cell l1=sheet.getCell("L2");
Cell m1=sheet.getCell("M2");
Cell n1=sheet.getCell("N2");
Cell o1=sheet.getCell("O2");
Cell p1=sheet.getCell("P2");
Cell q1=sheet.getCell("Q2");
Cell r1=sheet.getCell("R2");
Cell s1=sheet.getCell("S2");
Cell t1=sheet.getCell("T2");
Cell u1=sheet.getCell("U2");
Cell v1=sheet.getCell("V2");
Cell w1=sheet.getCell("W2");
Cell x1=sheet.getCell("X2");
Cell y1=sheet.getCell("Y2");
Cell z1=sheet.getCell("Z2");
Cell aa1=sheet.getCell("AA2");
Cell ab1=sheet.getCell("AB2");
Cell ac1=sheet.getCell("AC2");
Cell ad1=sheet.getCell("AD2");
Cell ae1=sheet.getCell("AE2");
Cell af1=sheet.getCell("AF2");
Cell ag1=sheet.getCell("AG2");
Cell ah1=sheet.getCell("AH2");
Cell ai1=sheet.getCell("AI2");
Cell aj1=sheet.getCell("AJ2");
Cell ak1=sheet.getCell("AK2");
Cell al1=sheet.getCell("AL2");
Cell am1=sheet.getCell("AM2");
Cell an1=sheet.getCell("AN2");
Cell ao1=sheet.getCell("AO2");
Cell ap1=sheet.getCell("AP2");
Cell aq1=sheet.getCell("AQ2");
Cell ar1=sheet.getCell("AR2");
Cell as1=sheet.getCell("AS2");
Cell at1=sheet.getCell("AT2");
Cell au1=sheet.getCell("AU2");
Cell av1=sheet.getCell("AV2");
Cell aw1=sheet.getCell("AW2");






recupa=a1.getContents();
recupb=b1.getContents();
recupc=c1.getContents();
recupd=d1.getContents();
recupe=e1.getContents();
recupf=f1.getContents();
recupg=g1.getContents();
recuph=h1.getContents();
recupi=i1.getContents();
recupj=j1.getContents();
recupk=k1.getContents();
recupl=l1.getContents();
recupm=m1.getContents();
recupn=n1.getContents();
recupo=o1.getContents();
recupp=p1.getContents();
recupq=q1.getContents();
recupr=r1.getContents();
recups=s1.getContents();
recupt=t1.getContents();
recupu=u1.getContents();
recupv=v1.getContents();
recupw=w1.getContents();
recupx=x1.getContents();
recupy=y1.getContents();
recupz=z1.getContents();
recupaa=aa1.getContents();
recupab=ab1.getContents();
recupac=ac1.getContents();
recupad=ad1.getContents();
recupae=ae1.getContents();
recupaf=af1.getContents();
recupag=ag1.getContents();
recupah=ah1.getContents();
recupai=ai1.getContents();
recupaj=aj1.getContents();
recupak=ak1.getContents();
recupal=al1.getContents();
recupam=am1.getContents();
recupan=an1.getContents();
recupao=ao1.getContents();
recupap=ap1.getContents();
recupaq=aq1.getContents();
recupar=ar1.getContents();
recupas=as1.getContents();
recupat=at1.getContents();
recupau=au1.getContents();
recupaw=av1.getContents();
recupaw=aw1.getContents();


EcrireExcelBD();

workbook.close();

} catch (IOException ex) {
Logger.getLogger(LectureFichier1.class.getName()).log(Level.SEVERE, null, ex);
}
}

public LectureFichier1(String tab) throws BiffException, ClassNotFoundException{
tableau=new String[49];
try {

Workbook workbook=Workbook.getWorkbook(new File("C:\\Users\\RICKYSTAR 007\\Documents\\Memoire stage\\FichierExcell.xls"));

Sheet sheet=workbook.getSheet(0);


/* if(tableau[0].equalsIgnoreCase("(BSC DPC or IP Address--BAF_BSC_PARC_0 003227)"))
{*/
do
{

for(int i=5;i

3 réponses

cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
30 août 2012 à 12:04
Aie mes yeux !
Difficile à lire ton code.
Au lieu de faire une variable pour chaque cellule, tu as beaucoup d'autre solutions
genre
getCell(int column, int row), dans une boucle for ça peut être plus pratique que d'utiliser le nom de cellule à la excel ("A2", etx ...).
ou
getRow(int row) qui te retourne directement un tableau de cellule.

En utilisant des boucle for sur un tableau Cell, pour faire tes traitements, tu pourrais déjà diviser par 2 ou 3 la taille de ton code.
0
cs_GodConan Messages postés 2113 Date d'inscription samedi 8 novembre 2003 Statut Contributeur Dernière intervention 6 octobre 2012 12
31 août 2012 à 06:57
ouilleeeeeeeeeeee

salut, ;o)
comment peut on ;o) prog de la sorte!!?? ;o)
t arriveras jamais à maintenir ton code ... ;o) en plus tu as généré les get/setter pour toutes ta liste de variable ;o): tien!! j ai dis "liste" ;o) ...

sinon!!! ;o) si ton volume de donnee n est pas trop important ce qui semble etre le cas, je te conseille de lire toute ta page et ensuite de faire les traitements sur le tableau d'objet obtenu...
cela peu paraitre plus long mais tu y gagneras en clareté.. ;o) et si le type de la donnée te pose probleme, lis toutes les cellules comme des chaine de caractere c est souvent le plus simple...



GodConan ;o)
0
Utilisateur anonyme
2 sept. 2012 à 17:24
Rien à dire, par contre quelqu'un a du collyre pour mes yeux x'D ?


--
Pylouq
Heureux sont ceux qui lisent le Réglement, ils ne finiront peut-être pas au bûcher.
0
Rejoignez-nous