- 遍歷Excel文件:
- FileInputStream fileInputStream = new FileInputStream( "c:/temp/test.xls" );
- POIFSFileSystem fileSystem = new POIFSFileSystem( fileInputStream );
- fileInputStream.close();
- HSSFWorkbook workbook = new HSSFWorkbook( fileSystem );
- for( int i = 0; i < workbook.getNumberOfSheets(); i++ ){
- HSSFSheet sheet = workbook.getSheetAt( i );
- if( sheet != null ){
- for( int j = sheet.getFirstRowNum(); j < sheet.getLastRowNum(); j++ ){
- HSSFRow row = sheet.getRow( j );
- if( null != row ){
- for( int k = row.getFirstCellNum(); k < row.getLastCellNum(); k++ ){
- HSSFCell cell = row.getCell( k );
- if( null != cell ){
- int type = cell.getCellType();
- switch( type ){
- case HSSFCell.CELL_TYPE_NUMERIC:
- System.out.print( cell.getNumericCellValue() + "/t" );
- break;
- case HSSFCell.CELL_TYPE_BOOLEAN:
- System.out.print( cell.getBooleanCellValue() + "/t" );
- break;
- case HSSFCell.CELL_TYPE_ERROR:
- System.out.print( cell.getErrorCellValue() + "/t" );
- break;
- case HSSFCell.CELL_TYPE_FORMULA:
- System.out.print( cell.getCellFormula() + "/t" );
- break;
- case HSSFCell.CELL_TYPE_STRING:
- System.out.print( cell.getRichStringCellValue() + "/t" );
- break;
- default:
- break;
- }
- }
- }
- System.out.println();
- }
- }
- }
- }