excel 2003 가져오기 excel 2007로 업그레이드

4819 단어 Excel
jxl은 excel 07 가져오기를 지원하지 않습니다. POI 및 jxls를 최신 버전으로 업그레이드합니다
 
1. 프로젝트에서 내려온jar 패키지를 추가합니다.
 
poi-ooxml-3.7.jar
poi-ooxml-schemas-3.7.jar
poi-3.7.jar (대체, 기존 포이 패키지 삭제)
jxls-core-1.0.jar (동상)
jxls-reader-1.0.jar (동상)
commons-jexl-2.1.1.jar (동상)
 
2. 가져오기를 수정하여 jxl을poi로 바꾸고poi의 패키지를 사용해야 합니다
JXL 가져오기Workbook wb = Workbook.getWorkbook(in);   Sheet sheet = wb.getSheet(sheetIndex);   int rows = sheet.getRows(); //   int cols = sheet.getColumns(); //   String[][] content = new String[rows - begin][cols];   for ( int i = begin; i < rows; i++) {   for ( int j = 0 ; j < cols; j++) {   Cell cell = sheet.getCell(j, i);   content[i - begin][j] = cell.getContents();   }   }
POI 가져오기Workbook wb = new XSSFWorkbook(in);   Sheet sheet = wb.getSheetAt(sheetIndex);   int rows = sheet.getLastRowNum()+ 1 ; //   int cols = sheet.getRow(begin).getLastCellNum(); //   String[][] content = new String[rows - begin][cols];   Cell tempCell = null ;   for ( int i = begin; i < rows; i++) {   Row r = sheet.getRow(i);   for ( int j = 0 ; j < cols; j++) {   tempCell = r.getCell(j);   String str = "" ;   if (tempCell.getCellType()==HSSFCell.CELL_TYPE_STRING){   str = tempCell.getStringCellValue();   } else if (tempCell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC){   str = String.valueOf(tempCell.getNumericCellValue());   }   content[i - begin][j] = str;   }   }
3. 템플릿에서 내보낸 HSSFWorkbook 워크북;org로 바꾸다.apache.poi.ss.usermodel.Workbook workbook;
원래HSSFWorkbook workbook;   String templateFileName = sc.getRealPath( "/" ) + templatePath;   try {   in = new BufferedInputStream( new FileInputStream(templateFileName));   XLSTransformer transformer = new XLSTransformer();   workbook = transformer.transformXLS(in, map);   OutputStream out = response.getOutputStream();   workbook.write(out);   out.flush();
고치다org.apache.poi.ss.usermodel.Workbook workbook;   String templateFileName = sc.getRealPath( "/" ) + templatePath;   try {   in = new BufferedInputStream( new FileInputStream(templateFileName));   XLSTransformer transformer = new XLSTransformer();   workbook = transformer.transformXLS(in, map);   OutputStream out = response.getOutputStream();   workbook.write(out);   out.flush();
	private static Workbook create(InputStream inp) throws IOException, InvalidFormatException {
		if (!inp.markSupported()) {
			inp = new PushbackInputStream(inp, 8);
		}
		if (POIFSFileSystem.hasPOIFSHeader(inp)) {
			return new HSSFWorkbook(inp);
		}
		if (POIXMLDocument.hasOOXMLHeader(inp)) {
			return new XSSFWorkbook(OPCPackage.open(inp));
		}
		throw new IllegalArgumentException(" excel poi ");
	}

좋은 웹페이지 즐겨찾기