POI读取2007 Excel文件

public static void readExcel(){
		
		InputStream is;
		try {
			is = new FileInputStream(new File("source/KPI指标分析(FTTX).xlsx"));
			XSSFWorkbook wb = new XSSFWorkbook(is);
			XSSFSheet sheet = wb.getSheet("ZH");
			for(int i=0;i<sheet.getNumMergedRegions();i++){
				CellRangeAddress merge = sheet.getMergedRegion(i);
				System.out.println(merge.getFirstColumn()+" "+merge.getLastColumn()+" "+merge.getFirstRow()+" "+merge.getLastRow());
			}
			
			for(Row row : sheet){
				for(Cell cell : row){
					switch (cell.getCellType()) {
	                case Cell.CELL_TYPE_STRING:
	                    System.out.println(cell.getRichStringCellValue().getString());
	                    break;
	                case Cell.CELL_TYPE_NUMERIC:
	                    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();
	            }
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

 

你可能感兴趣的:(Excel)