-
2021-06-09 02:32:40
推荐可以试用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();
}
}
更多相关内容 -
html转word
2019-01-17 10:51:32html网页转word,导出word。 -
java实现HTML转Word
2022-03-28 22:31:53java实现HTML转Word -
c# HTML转word源码
2018-08-13 11:32:23HTML转word ,基于.net 实现html转word,HTML转word ,基于.net 实现html转word, -
java将html转word并将图片打进word内,离线可看
2018-09-28 13:37:01完整项目包括所有jar包,完美支持html转word,并解决图片断网不能访问的问题。调用HtmlToWord类测试即可,注意修改调用文件的路径,因里面用到jacob,需要将jacob.dll拷贝到项目所在jre\bin目录下面 -
java Html转wordDemo和相关jar包.zip
2021-11-09 12:02:52Html转wordDemo和相关jar包。 解决java中html转word文档,转成功后的word文档在断网情况下无法显示图片问题。 搞了好多天,网上的帖子达不到效果。于是自己搞了个办法,亲测可用。 -
用jacob html 转word
2017-06-29 17:33:59整个代码只需要一个jacob的jar包就可以运行了。 当然,在下载的文件里面还有个调用系统库的dll文件需要放置在jre的bin目录下: 示例:D:\Java\jdk1.7.0_67\jre\bin\jacob-...这样代码就可以实现word转pdf,html 转word。 -
Html转Word(doc,docx),带样式以及图片
2019-04-09 22:10:59Html转Word(doc,docx),带样式以及图片转换,无缝对接 -
html 转 word
2013-08-29 14:52:43html 转 word 导出 word 方法一:html转word直接打开,并且可以分页,默认打开是页面视图 方法二:html转word 下载,可以分页,默认页面视图 -
html转Word(可批量转化但速度较慢,支持图片显示,图片在本地或网络都行)
2019-05-08 15:53:13html转word,之前找过一些但支持的不够全,自己在原有的基础上添加了部分通用功能, -
Java html转word 使用FreeMarker
2017-06-01 14:15:32java 将html转为word,使用Freemarker 比较好装好。方便好用。也可以转换成pdf格式。 -
java html转换word
2015-09-21 16:05:22java利用poi把html网友转换成word文档的小例子,包含程序代码和jar包。 -
HTML转Word.zip
2019-06-11 22:46:13c# html 转 Word 免费实用!简单易用,强烈推荐。 -
纯正html转word.rar
2019-08-15 09:03:46项目包括所有jar包,完美支持html转word,并解决图片断网不能访问的问题。调用HtmlToWord类测试即可,注意修改调用文件的路径,因里面用到jacob,需要将jacob.dll拷贝到项目所在jre\bin目录下面 -
通过Js实现Html转换成Word下载
2021-12-08 14:35:17比如文件下载,可以使用这个Js来实现,不用单独再去传word版本,还有就是有些文件还找不到word版,就可以用这个来实现 -
Html to word by open xml 基于Open Xml 实现的带页眉页脚页码的 Html 转Word 功能
2014-12-20 00:16:25基于Open Xml 实现的带页眉页脚页码的 Html 转Word 功能 跟 Microsoft.Office.Interop.Word 的 Com 组件相比优势如下: 1、服务器不用安装Office 即可生成Word 格式的文件; 2、服务器不用配置 繁琐的Com组件的权限... -
java实现docx文档在线编辑(docx转html,html转word,样式精准)
2019-11-08 10:30:33java实现docx转html,自定义标签属性,然后根据自定义的标签属性,将html转为word,可支持普通段落,图片、表格、单元格合并、文本字体、字体大小、段落对齐方式、删除线、下划线、粗体、斜体、背景颜色等 -
html转word.zip
2019-10-31 15:07:04html转word所需要的JS插件 -
C#实现HTML转WORD及WORD转PDF的方法
2020-09-03 08:06:46主要介绍了C#实现HTML转WORD及WORD转PDF的方法,涉及C#实现HTML、WORD及PDF等文件格式转换的相关技巧,需要的朋友可以参考下 -
Html转wordDemo和相关jar包
2017-11-15 22:48:56Html转wordDemo和相关jar包。 解决java中html转word文档,转成功后的word文档在断网情况下无法显示图片问题。 搞了好多天,网上的帖子达不到效果。于是自己搞了个办法,亲测可用。 -
富文本html转word,word文件合并.zip
2021-11-11 14:59:31java富文本html转word,word文件合并 -
可以将word转成html的js代码
2020-12-02 09:45:04WalkingPoison’s Word-to-HTML sample</TITLE> [removed] function saveword() { var oWordApp=new ActiveXObject(“Word.Application”); var oDocument=oWordApp.Documents.Open(“C:\\test.doc”); ... -
C# HtmlToWord 将HTML文件转换成word文档
2018-05-10 13:00:32批量的把html 文件转换成word,不需要电脑上有word软件!并且支持本地图片,html链接的图片必须在本地,可以把图片转换到word里! -
java中html转word方法以及用到的jar包
2012-09-19 14:21:06java中html转word方法以及用到的jar包,此方法是将html源码以字符串的形式进行转换,转换到word文件中,支持图片以及文字等信息。但是不支持视频等信息 -
phpword html转word word转html
2020-04-07 17:42:06phpword html转word word转html /** * +---------------------------------------------------------------------- * | ThinkPHP [ WE CAN DO IT JUST THINK ] * +------------------------------------------------...phpword 【composer require phpoffice/phpword】
html转word
word转html<?php /** * +---------------------------------------------------------------------- * | ThinkPHP [ WE CAN DO IT JUST THINK ] * +---------------------------------------------------------------------- * | Copyright (c) 2020 ahai574 All rights reserved. * +---------------------------------------------------------------------- * | Licensed ( ++++ahai574++++ ) * +---------------------------------------------------------------------- * | Author: 阿海 <764882431@qq.com> * +---------------------------------------------------------------------- * 处理导入excel 导入csv 导出xls xlsx csv */ namespace app\common\library; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\IOFactory; use PhpOffice\PhpWord\Shared\Html; use PhpOffice\PhpWord\Writer\Html as WriteHtml; class PHPWordLib { /** * 文件保存名称 不用写后缀 ,默认会使用下载驱动作为后缀 */ private $fileName = 'docx'; /** * 下载文件的驱动类 * 如Xls,Xlsx */ private $downloadClass = 'Word2007'; /** * 是下载还是保存至本地 默认是下载文件 */ private $isDownload = true; /** * 保存至服务器的路径 */ private $filePath = ""; /** * 保存至服务器的路径+文件名称 -- 这个不需要设置 ---自动使用 $filePath+$fileName+时间 */ private $saveFilePath = ""; /** * @param string html内容 */ private $wordData = ''; /** * 虽然说支持多种格式,但是我只要用来读写word即可 * 写入的文件类型 , 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html' */ private $writers = array('Word2007' => 'docx', 'HTML' => 'html'); public function __construct($config = []) { isset($config['fileName']) && $this->fileName = mb_convert_encoding($config['fileName'], 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); isset($config['downloadClass']) && $this->downloadClass = $config['downloadClass']; isset($config['wordData']) && $this->wordData = $config['wordData']; isset($config['isDownload']) && $this->isDownload = (bool) $config['isDownload']; $this->filePath = isset($config['filePath']) ? $config['filePath'] : "runtime/uploads/files/" . date("Y-m-d"); //文件名去除后缀 if (strripos($this->fileName, ".") !== false) { $this->fileName = substr($this->fileName, 0, strripos($this->fileName, ".")); } //如果是保存至本地 则设置保存的文件路径及名称,同样由于可能存在同名称 所以给加了一个随机数给这个文件名称,一般够用 $this->saveFilePath = !($this->isDownload) ? $this->filePath . "/" . $this->fileName . "_" . time() . rand(0, 1000) . "." . strtolower($this->writers[$this->downloadClass]) : ''; if (!file_exists($this->filePath)) { // @mkdir($this->filePath, 0777, true); @mkdir(iconv("UTF-8", "GBK", $this->filePath), 0777, true); } if (isset($config['downloadClass']) && !array_key_exists($config['downloadClass'], $this->writers)) { throw new \Exception("下载的驱动类,必须在writers中"); } } /** * 下载时的header头 */ private function header() { if ($this->isDownload) { // Redirect output to a client’s web browser (Xlsx) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $this->fileName . "." . strtolower($this->writers[$this->downloadClass]) . '"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 } else { // 确保文件没有缓存,在ios上可能会出现问题 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } } /** * @param String $data html内容 */ public function SetWordData($data) { $this->wordData = $data; return $this; } /** * 使用这个方法 downloadClass === * 下载文件支持: docx * 保存文件至服务器支持 .html,docx,...【如果需要更多格式,比如odt,记得在writers里面添加--必须是phpword里面支持的 pdf的话,我】 */ public function createServer() { //只用来下载docx 文件 if ($this->downloadClass !== 'Word2007' && $this->isDownload) { throw new \Exception("当前只支持docx文件下载"); } $this->header(); //设置允许的请求时间 @set_time_limit(5 * 60); $phpWord = new PhpWord(); $section = $phpWord->addSection(); $html = new Html(); $html::addHtml($section, $this->wordData, false, false); if ($this->isDownload) { $phpWord->save('php://output'); exit; } else { $phpWord->save($this->saveFilePath, $this->downloadClass); //返回文件路径 return $this->saveFilePath; } } /** * 将word文件转html代码 * @param string $filePath docx 文件路径 * @param boolean $saveHtml 是否保存html(依赖于isDownload,但是不会下载html页面) 否则输出html实体内容 * @return string html|path|document */ public function wordToHtml($filePath, $saveHtml = false) { if (!file_exists($filePath)) { throw new \Exception("文件不存在,请检查文件路径"); } //第二个参数是默认值,可以不填写 $phpWord = IOFactory::load($filePath, "Word2007"); $writer = IOFactory::createWriter($phpWord, "HTML"); if ((bool) $saveHtml) { //返回html实体内容 return $writer->getContent(); } else { if ($this->isDownload) { //直接显示 html $phpWord->save('php://output', 'HTML'); exit; } else { //保存至服务器 $phpWord->save($this->saveFilePath, 'HTML'); //返回文件路径 return $this->saveFilePath; } } } }
-
java使用POI实现html和word相互转换
2020-08-26 14:12:12主要为大家详细介绍了java使用POI实现html和word的相互转换,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 -
php实现将HTML页面转换成word并且保存的方法
2020-10-21 08:04:45主要介绍了php实现将HTML页面转换成word并且保存的方法,结合实例形式分析了PHPWord工具的功能与使用方法,具有一定参考借鉴价值,需要的朋友可以参考下