读取Excel后在JSP页面显示

读取.xls文档的代码 返回值是string类型
/**
	 * 读取Excel表格内容,生成纯文本
	 * @param is 输入流
	 * @return 返回文本字符串
	 * @throws IOException 抛出IO异常
	 */
	@SuppressWarnings("deprecation")
	public static String extractTextFromXLS(InputStream is)  throws IOException {    
    StringBuffer content  = new StringBuffer();    
    HSSFWorkbook workbook = new HSSFWorkbook(is); //创建对Excel工作簿文件的引用     

    for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {    
        if (null != workbook.getSheetAt(numSheets)) {    
            HSSFSheet aSheet = workbook.getSheetAt(numSheets); //获得一个sheet    

            for (int rowNumOfSheet = 0; rowNumOfSheet <= aSheet.getLastRowNum(); rowNumOfSheet++) {    
                if (null != aSheet.getRow(rowNumOfSheet)) {    
                    HSSFRow aRow = aSheet.getRow(rowNumOfSheet); //获得一行    

                    for (short cellNumOfRow = 0; cellNumOfRow <= aRow.getLastCellNum(); cellNumOfRow++) {    
                        if (null != aRow.getCell(cellNumOfRow)) {    
                            HSSFCell aCell = aRow.getCell(cellNumOfRow); //获得列值    
                                                                
                            if(aCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){    
                             content.append(aCell.getNumericCellValue());    
                            }else if(aCell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){    
                             content.append(aCell.getBooleanCellValue());    
                            }else {    
                             content.append(aCell.getStringCellValue());    
                            }    
                        }    
                    }    
                }    
            }    
        }  
       
    }    

    return content.toString();	
		
	}

你可能感兴趣的:(读取Excel后在JSP页面显示)