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
|
public class Main {
public static void main(String[] args) throws IOException, WriteException, BiffException {
// Permet d'ouvrir et de lire le fichier voulu
Workbook workbook = Workbook.getWorkbook(new File("E:\\A11_TOUTES_ENSEMBLE_après_purge_Avec_légendes_300_dpi.xls"));
// Permet de faire une copie du fichier excel source et permet d'acceder a la première feuille du fichier excel
WritableWorkbook workbookCopy = Workbook.createWorkbook(new File("E:\\A11_TOUTES_ENSEMBLE_après_purge_Avec_légendes_300_dpi.xls"), workbook);
WritableSheet sheetToEdit = workbookCopy.getSheet(0);
// Variable permettant d'enregistrer les informations extraites
Cell cell = null;
Cell cell1 = null;
Cell cell2 = null;
Cell cell3 = null;
// Suite de for permettant de recuperer les informations dans des colonnes specifiques
for(int j = 0; j < 3505; j++) {
cell = sheetToEdit.getCell(3, j);
// System.out.println(cell.getContents());
}
for(int j = 3507; j < sheetToEdit.getRows(); j++) {
cell1 = sheetToEdit.getCell(3,j);
// System.out.println(cell1.getContents());
}
for(int j = 0; j < 3505; j++) {
cell2 = sheetToEdit.getCell(9, j);
// System.out.println(cell2.getContents());
}
for(int j = 3507; j < sheetToEdit.getRows(); j++) {
cell3 = sheetToEdit.getCell(9,j);
// System.out.println(cell3.getContents());
}
// Boucle for permettant de changer le contenu de toutes les lignes dans une colonne specifique
for(int j = 0; j < 3505; j++) {
WritableCell c = sheetToEdit.getWritableCell(j,9);
if(cell.equals(cell1) && cell2.equals(cell3)) {
String cont = c.getContents();
System.out.println("contenu actuel"+ cont);
Label label = (Label) c;
label.setString(cell2+"_"+cell3);
}
}
// Permet decrire et de fermer le fichier et de rafraichir la memoire
workbookCopy.write();
workbookCopy.close();
}
} |
Partager