POI 2007 Excel 파일 읽기

1700 단어 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();
		}
		
		
	}

좋은 웹페이지 즐겨찾기