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
|
package poi;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class BlankTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Module de remplacement de méthode auto-généré
try {
Workbook wb = WorkbookFactory.create(BlankTest.class.getClass().getResourceAsStream("/poi.xls"));
Sheet sheet = wb.getSheetAt(0);
System.out.println("nbLignes= "+sheet.getLastRowNum());
System.out.println("nbLignesPhy= "+sheet.getPhysicalNumberOfRows());
for (int i = 0; i<sheet.getPhysicalNumberOfRows();i++) {
Row r = sheet.getRow(i);
System.out.println("nbCols= "+r.getLastCellNum());
System.out.println("nbColsPhy= "+r.getPhysicalNumberOfCells());
for(int j = 0; j < r.getLastCellNum(); j++) {
Cell c = r.getCell(j);
if(c == null) {
System.out.print("null ");
} else {
System.out.print("col indx: "+c.getColumnIndex()+" ");
System.out.print("cell type: "+c.getCellType()+" ");
if(c.getCellType() == Cell.CELL_TYPE_BLANK) {
System.out.print("vide");
} else if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
System.out.print("numeric "+c.getNumericCellValue());
} else if (c.getCellType() == Cell.CELL_TYPE_STRING) {
System.out.print("String "+c.getStringCellValue());
}
System.out.print(" ");
}
}
System.out.println();
}
} catch (InvalidFormatException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
} catch (IOException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}
}
} |
Partager