用poi实现医生转html

  

废话,不多说直接上代码。

  

一,医生转html,并且带文件夹

  
 <代码>/*字转html
  * html转图片
  * @param tagPath转换html文件之后,所带的图片附件文件夹
  * @param sourceFileName源文件
  * @param outPath输出文件xx.html
  * @return
  * @throws例外
  */tagPath docToHtml公共静态字符串(字符串,
  sourceFileName的字符串,字符串outPath){抛出异常
  文件文件=新文件(tagPath);
  如果(! file.exists ()) {
  file.mkdirs ();
  }
  HWPFDocument wordDocument=new HWPFDocument(新FileInputStream (sourceFileName));
  org.w3c.dom。.newDocument .newDocumentBuilder文档文档=DocumentBuilderFactory.newInstance () () ();
  WordToHtmlConverter WordToHtmlConverter=new WordToHtmlConverter(文档);//保存图片,并返回图片的相对路径
  wordToHtmlConverter。setPicturesManager(内容、pictureType名称、宽度、高度)→{
  尝试(FileOutputStream=new FileOutputStream (tagPath +名字)){
  out.write(内容);
  }捕捉(异常e) {
  e.printStackTrace ();
  }
  返回“图像/?名称;
  });
  wordToHtmlConverter.processDocument (wordDocument);
  org.w3c.dom。文档htmlDocument=wordToHtmlConverter.getDocument ();
  DOMSource DOMSource=new DOMSource (htmlDocument);
  StreamResult StreamResult=new StreamResult(新文件(outPath));
  TransformerFactory tf=TransformerFactory.newInstance ();
  变压器序列化器=tf.newTransformer ();
  serializer.setOutputProperty (OutputKeys。编码,“utf - 8”);
  serializer.setOutputProperty (OutputKeys。缩进:“是的”);
  serializer.setOutputProperty (OutputKeys。方法,“html”);
  序列化器。变换(domSource streamResult);
  返回outPath;
  } 
  

<强>调用:

  
 <代码>/* *医生
  *转html
  */字符串tagPath=" D: \ \ red_ant_file \ \ 20180915 \ \ \ \“;
  字符串sourcePath=" D: \ \ red_ant_file \ \ 20180915 \ \ RedAnt的实验作业. doc”;
  字符串outPath=" D: \ \ red_ant_file \ \ 20180915 \ \ 123. html”;
  尝试{
  AllServiceIsHere。docToHtml (tagPath路径,outPath);
  }捕捉(异常e) {//TODO自动生成的catch块
  e.printStackTrace ();
  } 
  

演示:   

用poi实现医生转html

  

走你:   

用poi实现医生转html

  

用poi实现医生转html

  

用poi实现医生转html

用poi实现医生转html