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
|
String repertoire = null;
String inFilename = null;
String outFilename = null;
String lecture = null;
POIFSFileSystem fs = null;
FileOutputStream file = null;
FileOutputStream fileOut = null;
HSSFWorkbook workbook = null;
HSSFSheet sheet = null;
HSSFSheet newSheet = null;
repertoire = "C:\\datas\\";
inFilename = "test.xls;
outFilename = repertoire + "Donnees_param_" +
inFilename;
fs = new POIFSFileSystem(new FileInputStream(new File(inFilename)));
fileOut = new FileOutputStream(new File(outFilename));
workbook = new HSSFWorkbook(fs);
sheet = workbook.getSheetAt(0);
workbook = new HSSFWorkbook();
newSheet = workbook.createSheet("Feuille1");
int nbRow = sheet.getPhysicalNumberOfRows();
for(int i = 0 ; i < nbRow ; i++) {
HSSFRow newRow = newSheet.createRow(i);
HSSFRow row = sheet.getRow(i);
// cell
for(short j = (short) 0 ; j < (short) 64 ; j++) {
HSSFCell cel = row.getCell(j);
// je ne récupere que la colonne 0
if ( j < (short) 1){
HSSFCell newCell = newRow.createCell(j);
if ( !cel.equals(null) ) {
switch(cel.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellType(HSSFCell.CELL_TYPE_STRING);
newCell.setCellValue(cel.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
newCell.setCellValue(cel.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
newCell.setCellType(HSSFCell.CELL_TYPE_STRING);
newCell.setCellValue(cel.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
newCell.setCellValue(cel.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
newCell.setCellValue("");
break;
}//switch
}
}
// puis je ne recupere ici que les colonnes de 11 à 62
else if ( j > (short) 10 && j < (short) 63) {
HSSFCell newCell = newRow.createCell((short) (j-10));
if ( !cel.equals(null) ) {
switch(cel.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellType(HSSFCell.CELL_TYPE_STRING);
newCell.setCellValue(cel.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
newCell.setCellValue(cel.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
newCell.setCellType(HSSFCell.CELL_TYPE_STRING);
newCell.setCellValue(cel.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
newCell.setCellValue(cel.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
newCell.setCellValue("");
break;
}//switch
}
}
}
workbook.write(fileOut);
fileOut.close(); |
Partager