java实现在线预览----poi操作excel转html及03、07版本兼容问题

poi操作excel转html及其兼容问题


excel03是读取文件整个内容转为字符串存进html,excel07是读取文件内容拼成字符串存进html

       /**
	 * excel03转html
	 * filename:要读取的文件所在文件夹
	 * filepath:文件名
	 * htmlname:生成html名称
	 * path:html存放路径
	 * */
	 public static void PoiExcelToHtml (HttpServletRequest request,String filepath,String sourceid) throws Exception {
		 String htmlname="exportExcel"+sourceid+".html";
		 String path=request.getSession().getServletContext().getRealPath("/view/excel");
		 fileExists(path);//此方法是判断目录文件夹是否存在,这里就不贴了
	    String filename=request.getSession().getServletContext().getRealPath("/vod/mp4");
	    InputStream input=new FileInputStream(filename+"/"+filepath);
	    HSSFWorkbook excelBook=new HSSFWorkbook(input);
	    ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter (DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() );
	    excelToHtmlConverter.processWorkbook(excelBook);//excel转html
	    Document htmlDocument =excelToHtmlConverter.getDocument();
	    ByteArrayOutputStream outStream = new ByteArrayOutputStream();//字节数组输出流
	    DOMSource domSource = new DOMSource (htmlDocument);
	    StreamResult streamResult = new StreamResult (outStream);
	    /** 将document中的内容写入文件中,创建html页面 */
	    TransformerFactory tf = TransformerFactory.newInstance();
	    Transformer 

你可能感兴趣的:(java,poi在线预览,java,html,poi,兼容,excel)