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
| private Workbook prestataire,prestataire1,prestataire2,prestataire3;
private WritableWorkbook copie;
private WritableSheet sheetEnSortie;
private int offset,temp;
private Sheet shPrestataire1,shPrestataire2,shPrestataire3;
//Nombre de fichier à consolider
private int nbFic;
public Excel(){
try {
prestataire = Workbook.getWorkbook(new File("D:/Documents/S607495/FichierPrestataire2.xls"));
prestataire1=Workbook.getWorkbook(new File("D:/Documents/S607495/FichierPrestataire2.xls"));
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
copie = Workbook.createWorkbook(new File("D:/Documents/S607495/output.xls"),prestataire);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Copie intégrale du fichier (avec en-tête)
sheetEnSortie=copie.getSheet(0);
shPrestataire1=prestataire1.getSheet(0);
offset= sheetEnSortie.getColumn(4).length;
System.out.println("la valeur de k est = "+ offset);
Cell[] c=shPrestataire1.getColumn(4);
System.out.println(c.length);
temp=c.length-1;
while(c[temp].getContents()=="") temp--;
System.out.println("temp= " + temp);
for (int i = 6; i < temp+1; i++)
{
for (int j = 0 ; j < shPrestataire1.getColumns() ; j++)
{
String sTemp;
sTemp=shPrestataire1.getCell(j,i).getContents();
Label label;
sTemp=shPrestataire1.getCell(j, i).getContents();
label = new Label(j, i+offset-6, sTemp);
//System.out.println("hack = "+sTemp );
try {
sheetEnSortie.addCell(label);
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
try {
copie.write();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
copie.close();
prestataire.close();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager