本文主要是介绍POI代碼,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
遍歷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();}}}}
这篇关于POI代碼的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!