如何在java中读/写excel复选框状态

时间:2014-01-24 09:29:27

标签: java excel radio

如何从(true or false)获取广播价值excel2010?在java中,谢谢!

1 个答案:

答案 0 :(得分:1)

首先,您必须下载Apache POI库。然后,您可以获得以下给定代码的帮助,以实现您想要的目标。

FileInputStream file = new FileInputStream(new File("d:/file.xls"));

//Get the workbook instance for XLS file 
HSSFWorkbook workbook = new HSSFWorkbook(file);

//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(0);

//Iterate through each rows from first sheet
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()) {
    Row row = rowIterator.next();

    //For each row, iterate through each columns
    Iterator<Cell> cellIterator = row.cellIterator();
    while(cellIterator.hasNext()) {

        Cell cell = cellIterator.next();

        switch(cell.getCellType()) {
            case Cell.CELL_TYPE_BOOLEAN:
                System.out.print(cell.getBooleanCellValue() + "\t\t");
                break;
            case Cell.CELL_TYPE_NUMERIC:
                System.out.print(cell.getNumericCellValue() + "\t\t");
                break;
            case Cell.CELL_TYPE_STRING:
                System.out.print(cell.getStringCellValue() + "\t\t");
                break;
        }
    }
    System.out.println("");
}

有关详细信息,请查看此link