使用java读取一列excel表

Pri*_*ube 3 java excel apache-poi

我有一张excel表.我想编写一个方法,该方法将参数作为要读取的列号,并返回由该列中的所有数据组成的数组.

然后将该列元素放在xml工作表中.我怎么写一个方法来做到这一点?

unc*_*ons 7

使用Apache POI.您可以在其使用页面中找到示例.

Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
    for (Cell cell : row) {
    // Here you might have to use the cell number to limit what you want.
        CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
        System.out.print(cellRef.formatAsString());
        System.out.print(" - ");

        switch(cell.getCellType()) {
      case Cell.CELL_TYPE_STRING:
        System.out.println(cell.getRichStringCellValue().getString());
        break;
      case Cell.CELL_TYPE_NUMERIC:
        if(DateUtil.isCellDateFormatted(cell)) {
          System.out.println(cell.getDateCellValue());
        } else {
          System.out.println(cell.getNumericCellValue());
        }
        break;
      case Cell.CELL_TYPE_BOOLEAN:
        System.out.println(cell.getBooleanCellValue());
        break;
      case Cell.CELL_TYPE_FORMULA:
        System.out.println(cell.getCellFormula());
        break;
      default:
        System.out.println();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)