如何将word转为html_word转html工具

如何将word转为html_word转html工具推荐可以试用FreeSpire.DocforJava免费控件哦,它支持将htmlstring和htmlfile转word,代码操作简单,转换效果也很好。Htmlfile转wordimportcom.spire.doc.*;importcom.spire.doc.documents.XHTMLValidationType;publicclasshtmlFileToWord{pu…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

推荐可以试用Free Spire.Doc for Java免费控件哦,它支持将html string和html file转word,代码操作简单,转换效果也很好。

Html file转wordimport com.spire.doc.*;

import com.spire.doc.documents.XHTMLValidationType;

public class htmlFileToWord {

public static void main(String[] args) {

String inputFile=”data/InputHtmlFile.html”;

String outputFile=”output/htmlFileToWord.docx”;

//open an html file.

Document document = new Document();

document.loadFromFile(inputFile, FileFormat.Html, XHTMLValidationType.None);

//save to a Word document.

document.saveToFile(outputFile, FileFormat.Docx);

}

}

Html string 转Wordimport com.spire.doc.*;

import java.io.*;

public class htmlStringToWord {

public static void main(String[] args) throws IOException {

String inputHtml = “data/InputHtml.txt”;

String outputFile=”output/htmlStringToWord.docx”;

Document document = new Document();

//add a section.

Section sec = document.addSection();

String htmlText = readTextFromFile(inputHtml);

//add a paragraph and append html string.

sec.addParagraph().appendHTML(htmlText);

//save to a Word file.

document.saveToFile(outputFile, FileFormat.Docx);

}

public static String readTextFromFile(String fileName) throws IOException{

StringBuffer sb = new StringBuffer();

BufferedReader br = new BufferedReader(new FileReader(fileName));

String content = null;

while ((content = br.readLine()) != null) {

sb.append(content);

}

return sb.toString();

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182781.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python 判断文件是否存在,删除文件

    python 判断文件是否存在,删除文件#判断文件是否存在,path为文件路径importosos.path.exists(path)#删除文件,path为文件路径importosos.remove(path)

    2022年6月18日
    38
  • 秒懂约瑟夫环

    秒懂约瑟夫环转自:https://blog.csdn.net/byn12345/article/details/79487253约瑟夫生者死者游戏约瑟夫游戏的大意:30个游客同乘一条船,因为严重超载,加上风浪大作,危险万分。因此船长告诉乘客,只有将全船一半的旅客投入海中,其余人才能幸免于难。无奈,大家只得同意这种办法,并议定30个人围成一圈,由第一个人数起,依次报数,数到第9人,便把他投入大海…

    2022年6月4日
    28
  • 【Linux】内核编程中的EXPORT_SYMBOL()

    【Linux】内核编程中的EXPORT_SYMBOL()查看符号导出结果命令:以EXPORT_SYMBOL(export_symbol_server)为例:$cat/proc/kallsyms|grepexport_symbol_server一:EXPORT_SYMBOL()宏定义相关定义如下#define___PASTE(a,b)a##b#define__PASTE(a,b)___PASTE(a,b)#define__UNIQUE_ID(prefix)__PASTE(__PASTE(__UNIQUE_ID_,p

    2022年7月16日
    20
  • jsonignore注解(jsonignore根据条件生效)

    当要将list作为一个json传到前端时有可能会出现死循环。处理方法:在实体类中对不需要的属性加上@JsonIgnore

    2022年4月11日
    339
  • 单片机红外传感器_基于51单片机的声音传感器

    单片机红外传感器_基于51单片机的声音传感器一、背景介绍我们工作久了,久坐导致的毛病就显现出来了,腰酸背痛颈椎疼,最近看到利用番茄钟工作法挺好,工作25分钟,休息5分钟,既能调整工作节奏,避免精力过分消耗,也能避免久坐导致的身体问题。我刚开始使用闹钟做提醒,后来尝试番茄钟软件,但是都要手动去操作手机,拿起手机看到信息,然后就会去处理手机上的事情了,起不到作用…直到有一天收拾东西看到了我大学期间基于51单片机做的一个电子设计,激起了我的灵感,开始了基于51单片机的自动番茄钟,久坐提醒神器的设计和制作。整体方案硬件部分继承了大学时焊接的电路板,更

    2022年10月1日
    0
  • python检测字符串乱码

    python检测字符串乱码importchardetf=open(‘test.txt’,’rb’)f_read=f.read()f_charInfo=chardet.detect(f_read)print(f_charInfo)#f_charInfo的输出是这样的的一个字典{‘confidence’:0.99,’encoding’:’utf-8′}转载于:https://www.cnblogs.c…

    2022年5月17日
    88

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号