[]
        
(Showing Draft Content)

获取数据

该例子展示了GcExcel与POI获取数据的代码


GcExcel 获取数据

//GcExcel 创建worksheet
Workbook wb = new Workbook();
IWorksheet sheet1 = wb.getWorksheets().get(0);
Object[][] values = (Object[][]) sheet1.getRange("A1:Z26").getValue();

POI 获取数据

//POI 创建worksheet
Workbook wb = new XSSFWorkbook();
wb.createSheet();
for (Sheet sheet : wb) {
    for (Row row : sheet) {
        for (Cell cell : row) {
            switch (cell.getCellType()) {
                case Cell.CELL_TYPE_STRING:
                    cell.getRichStringCellValue().getString();
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    if (DateUtil.isCellDateFormatted(cell)) {
                        cell.getDateCellValue();
                    } else {
                        cell.getNumericCellValue();
                    }
                    break;
                case Cell.CELL_TYPE_BOOLEAN:
                    cell.getBooleanCellValue();
                    break;
                case Cell.CELL_TYPE_FORMULA:
                    cell.getCellFormula();
                    break;
                default:
                    //do nothing
            }
        }
    }
}