Excel을 zip 가져오기로 압축
@RequestMapping("testImportZip")
    public void testImportZip(MultipartFile file) throws Exception {
    	if(null != file) {
    		InputStream inputStream = file.getInputStream();
    		Charset gbk = Charset.forName("gbk");
    		ZipInputStream zipInputStream  = new ZipInputStream(inputStream,gbk);
    		ZipEntry zipEntry;
    		while((zipEntry = zipInputStream.getNextEntry()) != null) {
    			String name = zipEntry.getName();
    			System.out.println("name=================================================>"+name);
    			long size = zipEntry.getSize();
    			
    			
    			//  new HSSFWorkbook(InputStream) new XSSFWorkbook(InputStream) ,  zipInputStream , zipInputStream 
    			ByteArrayOutputStream bout = new ByteArrayOutputStream();
                byte[] temp = new byte[1024];
                byte[] buf = null;
                int length = 0;
                while ((length = zipInputStream.read(temp, 0, 1024)) != -1) {
                    bout.write(temp, 0, length);
                }
                buf = bout.toByteArray();
                bout.close();
                
    			ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buf);
    			
    			
    			String fileType = name.substring(name.lastIndexOf("."), name.length());
    			HSSFWorkbook hworkbook = null;
	            XSSFWorkbook xworkbook = null;
	            Sheet sheet = null;
    			if(".xls".equalsIgnoreCase(fileType)){
                    hworkbook = new HSSFWorkbook(byteArrayInputStream);
                    sheet = hworkbook.getSheetAt(0);
                }else if(".xlsx".equalsIgnoreCase(fileType)){
                    xworkbook = new XSSFWorkbook(byteArrayInputStream);
                    sheet = xworkbook.getSheetAt(0);
                }
    			if(null != sheet) {
    				// 
    				for (int i = 2; i <= sheet.getLastRowNum(); i++) {
    					Row row = sheet.getRow(i);
    					if (row != null) {
    						for (Cell cell : row) {
    							String cellvalue;
								if (cell != null) {
									switch (cell.getCellType()) {
									case Cell.CELL_TYPE_NUMERIC: {
										cell.setCellType(Cell.CELL_TYPE_STRING);
										cellvalue = cell.getStringCellValue();
										break;
									}
									case Cell.CELL_TYPE_FORMULA: {
										cellvalue = cell.getCellFormula();
										break;
									}
									case Cell.CELL_TYPE_STRING:
										cellvalue = cell.getStringCellValue();
										break;
									default:
										cellvalue = "";
									}
								} else {
									cellvalue = "";
								}
								System.out.println(cellvalue);
    						}
    					}
    					
    				}
    			}
    			
    		}
    		
    		if(null != zipInputStream) {
    			zipInputStream.close();
    		}
    	}
    	
    }  이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.