用Poi 转word docx 跟 doc 格式

本文介绍了如何利用Java的Poi库进行Word文档格式转换,包括从docx到doc以及doc到docx的操作,详细讲解了所需jar包及转换步骤。
摘要由CSDN通过智能技术生成
//辅助 03 写入文件 
public static void writeFile(String content, String path) {    
	        FileOutputStream fos = null;    
	        BufferedWriter bw = null;    
	        try {    
	            File file = new File(path);    
	            fos = new FileOutputStream(file);    
	            bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8"));    
	            bw.write(content);    
	        } catch (FileNotFoundException fnfe) {    
	            fnfe.printStackTrace();    
	        } catch (IOException ioe) {    
	            ioe.printStackTrace();    
	        } finally {    
	            try {    
	                if (bw != null)    
	                    bw.close();    
	                if (fos != null)    
	                    fos.close();    
	            } catch (IOException ie) {    
	            	ie.printStackTrace();
	            }    
	        }    
	    }
		
//将Doc文件 转成html 并输出
 public static void convert2Html(String fileName, String outPutFile)    
		            throws TransformerException, IOException,   
		            ParserConfigurationException {
			 	
			 	System.out.println("outPutFile========="+outPutFile);
		        HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile));    
		        WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(    
		                DocumentBuilderFactory.newInstance().newDocumentBuilder()    
		                        .newDocument());    
		         wordToHtmlConverter.setPicturesManager( new PicturesManager()    
		         {    
		             public String savePicture( byte[] content,    
		                     PictureType pictureType, String suggestedName,    
		                     float widthInches, float heightInches )    
		             {    
		                 return suggestedName;    
		             }    
		         } );    
		        wordToHtmlConverter.processDocument(wordDocument);    
		        //save pictures    
		        List pics=wordDocument.getPicturesTable().getAllPictures();    
		        if(pics!=null){    
		            for(int i&
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值