java将word转换为html(代码)

java将word转换为html(代码)

编程我该学前端、后端还是全栈?

作为一名开发者,你可能会想:2019 年最好的软件开发技术和编程语言会是什么?它们又是如何被应用在软件开发当中的?如果你在思考这个问题,那就来对地方了。

notepad怎么批量注释

选中需要注释的代码,点击“编辑”,在下拉菜单中选择“注释/取消注释”,然后在子菜单中选择注释方式即可。也可以通过快捷键进行注释,单行、多行注释:Ctrl+K;区块注释:Ctrl+Q。

代码:

public static void main(String[] args) throws Exception {
    String filePath = "C:/Users/Administrator/Desktop/92个诊疗计划及临床途径/";
    File file = new File(filePath);
    File[] files = file.listFiles();
    String name = null;
    for (File file2 : files) {
        Thread.sleep(500);
        name = file2.getName().substring(0, file2.getName().lastIndexOf("."));
        System.out.println(file2.getName());
        if (file2.getName().endsWith(".docx") || file2.getName().endsWith(".DOCX")) {
            CaseHtm.docx(filePath ,file2.getName(),name +".htm");
        }else{
            CaseHtm.dox(filePath ,file2.getName(),name +".htm");
        }
    
    }
}
/**
* 转换docx
* @param filePath
* @param fileName
* @param htmlName
* @throws Exception
*/
public static void docx(String filePath ,String fileName,String htmlName) throws Exception{
    final String file = filePath + fileName;
    File f = new File(file);  
    // ) 加载word文档天生 XWPFDocument对象
    InputStream in = new FileInputStream(f);
    XWPFDocument document = new XWPFDocument(in);
    // ) 剖析 XHTML设置 (这里设置IURIResolver来设置图片寄存的目次)
    File imageFolderFile = new File(filePath);
    XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(imageFolderFile));
    options.setExtractor(new FileImageExtractor(imageFolderFile));
    options.setIgnoreStylesIfUnused(false);
    options.setFragment(true);
    // ) 将 XWPFDocument转换成XHTML
    OutputStream out = new FileOutputStream(new File(filePath + htmlName));
    XHTMLConverter.getInstance().convert(document, out, options);
}
/**
* 转换doc
* @param filePath
* @param fileName
* @param htmlName
* @throws Exception
*/
public static void dox(String filePath ,String fileName,String htmlName) throws Exception{
    final String file = filePath + fileName;
    InputStream input = new FileInputStream(new File(file));
    HWPFDocument wordDocument = new HWPFDocument(input);
    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
    //剖析word文档
    wordToHtmlConverter.processDocument(wordDocument);
    Document htmlDocument = wordToHtmlConverter.getDocument();
    
    File htmlFile = new File(filePath + htmlName);
    OutputStream outStream = new FileOutputStream(htmlFile);
    
    DOMSource domSource = new DOMSource(htmlDocument);
    StreamResult streamResult = new StreamResult(outStream);
    
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer serializer = factory.newTransformer();
    serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.setOutputProperty(OutputKeys.METHOD, "html");
    
    serializer.transform(domSource, streamResult);
    outStream.close();
}

pom.xml设置:

<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.document</artifactId>
    <version>1.0.5</version>
</dependency>
<dependency>  
    <groupId>fr.opensagres.xdocreport</groupId>  
    <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>  
    <version>1.0.5</version>  
</dependency>
    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.12</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>3.12</version>
</dependency>

notepad怎么取消全屏

可打开双窗口,在分窗口中又可打开多个子窗口,允许快捷切换全屏显示模式(F11),支持鼠标滚轮改变文档显示比例;也可以通过点击菜单栏中【视图】—【切换全屏模式】来进入或退出全屏模式。

Up Next:

navicat for oracle怎样下载安装

navicat for oracle怎样下载安装