问题描述
rt,要怎么做,不要03的
解决方案
解决方案二:
用poi读取word文件然后转化成html。之前项目中做过,不过貌似样式有点问题
解决方案三:
笨方法,读取excel然后appendhtml标签,最后输出html文件,应该是可以的,呵呵没有做过。。。
解决方案四:
/***读取word文件的内容,并转为html*@paramfileName*@paramoutPutFile*@throwsTransformerException*@throwsIOException*@throwsParserConfigurationException*/publicvoidconvert2Html(StringfileName,StringoutPutFile)throwsTransformerException,IOException,ParserConfigurationException{HWPFDocumentwordDocument=newHWPFDocument(newFileInputStream(fileName));//WordToHtmlUtils.loadDoc(newFileInputStream(inputFile));WordToHtmlConverterwordToHtmlConverter=newWordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());wordToHtmlConverter.setPicturesManager(newPicturesManager(){publicStringsavePicture(byte[]content,PictureTypepictureType,StringsuggestedName,floatwidthInches,floatheightInches){returnsuggestedName;}});wordToHtmlConverter.processDocument(wordDocument);//savepictures保存图片Listpics=wordDocument.getPicturesTable().getAllPictures();if(pics!=null){for(inti=0;i<pics.size();i++){Picturepic=(Picture)pics.get(i);System.out.println();try{pic.writeImageContent(newFileOutputStream(filePath+File.separator+pic.suggestFullFileName()));}catch(FileNotFoundExceptione){e.printStackTrace();}}}org.w3c.dom.DocumenthtmlDocument=wordToHtmlConverter.getDocument();ByteArrayOutputStreamout=newByteArrayOutputStream();if(out!=null){out.flush();}DOMSourcedomSource=newDOMSource(htmlDocument);StreamResultstreamResult=newStreamResult(out);TransformerFactorytf=TransformerFactory.newInstance();Transformerserializer=tf.newTransformer();serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");serializer.setOutputProperty(OutputKeys.INDENT,"yes");serializer.setOutputProperty(OutputKeys.METHOD,"html");serializer.transform(domSource,streamResult);out.close();writeFile(newString(out.toByteArray()),outPutFile);}/***输入流写入html*@paramcontent*@parampath*/publicvoidwriteFile(Stringcontent,Stringpath){FileOutputStreamfos=null;BufferedWriterbw=null;try{Filefile=newFile(path);fos=newFileOutputStream(file,true);bw=newBufferedWriter(newOutputStreamWriter(fos,"UTF-8"));bw.write(content);}catch(FileNotFoundExceptionfnfe){fnfe.printStackTrace();}catch(IOExceptionioe){ioe.printStackTrace();}finally{try{if(bw!=null)bw.close();if(fos!=null)fos.close();}catch(IOExceptionie){}}}
解决方案五:
楼上的方法是支持2003的,不支持2007的