2015年3月20日金曜日

Apache POIでエクセルファイルを読み込むサンプルコード


         ByteArrayInputStream bis = null;
            Workbook workbook = null;
            try {
                bis = new ByteArrayInputStream(file.getBytes());            
                
                if (file.getOriginalFilename().endsWith("xls")) {
                    workbook = new HSSFWorkbook(bis);
                } else if (file.getOriginalFilename().endsWith("xlsx")) {
                    workbook = new XSSFWorkbook(bis);
                } else {
                    throw new IllegalArgumentException("Received file does not "
                    + "have a standard excel extension.");
                }
                
                // Iterate rows
                for ( Row row : workbook.getSheetAt(0) ) {                

                }
                
                ....
                
              }


http://stackoverflow.com/questions/14740727/upload-excel-file-into-database-using-apache-poi-and-spring-framework

0 件のコメント:

コメントを投稿