资源简介
Itext实现Html转化为Doc源码、Doc中部分代码为html转化

代码片段和文件信息
package com.spb.SpringBootDemo.rest;
import java.awt.Color;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.List;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.styleSheet;
import com.lowagie.text.pdf.baseFont;
import com.lowagie.text.rtf.RtfWriter2;
/**
* HTML 转换 Word
* @author Lsd 2018-01-19
*
*/
public class HTML2Word {
public static void main(String[] args) throws Exception {
String filepath = “C:/test/“;
//创建 POIFSFileSystem 对象
POIFSFileSystem poifs = new POIFSFileSystem();
//获取DirectoryEntry
DirectoryEntry directory = poifs.getRoot();
//创建输出流
OutputStream out = new FileOutputStream(filepath+“2003.doc“);
try {
//创建文档1.格式2.HTML文件输入流
InputStream is = new FileInputStream(filepath+“2003.html“);
directory.createDocument(“WordDocument“is );
//写入
poifs.writeFilesystem(out);
//释放资源
out.close();
System.out.println(“success“);
String htmlContent = “1222 First Row “
+ “Second你好 Row
“;
insertHtml2Doc(htmlContent);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 获取 class path 中的文件流
* @param name 名称
* @return InputStream
*/
public static InputStream getInputStream(String name){
return Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
}
public static void insertHtml2Doc(String htmlContent) throws IOException DocumentException{
// 设置中文字体
OutputStream out = new FileOutputStream(“c:/test/a.doc“);
Document document = new Document(PageSize.A4);
RtfWriter2.getInstance(document out);
document.open();
Paragraph context = new Paragraph();
//String htmlContent = “
“;
styleSheet ss = new styleSheet();
ss.loadTagstyle(“table“ “border“ “1000“);
ss.loadTagstyle(“tr“ “width“ “10“);
List htmlList = com.lowagie.text.html.simpleparser.HTMLWorker.parseToList(new StringRead
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3072 2018-01-19 15:15 test\2003.doc
文件 604 2018-01-19 08:58 test\2003.html
文件 0 2018-01-19 08:42 test\2007.docx
文件 65788 2018-01-19 15:23 test\2007.html
文件 314 2018-01-19 11:26 test\a.files\colorschememapping.xm
文件 233 2018-01-19 11:26 test\a.files\filelist.xm
文件 3432 2018-01-19 11:26 test\a.files\header.htm
文件 3116 2018-01-19 11:26 test\a.files\themedata.thmx
文件 4277 2018-01-19 15:44 test\HTML2Word.java
..A..H. 162 2018-01-19 15:15 test\~$a.doc
目录 0 2018-01-19 11:26 test\a.files
目录 0 2018-01-19 08:39 test\image
目录 0 2018-01-19 15:50 test
文件 31267 2018-01-19 15:50 test\a.doc
----------- --------- ---------- ----- ----
112265 14
相关资源
- uploadifive1.2.2 uploadify HTML5
- 管理系统HTML模板
- 非常漂亮的导航菜单(html)
- 网页文件HTML
-
html中获取xm
l数据 - HTML AJAX(手写ajax)显示数据库数据
- HTML5 CSS3 :canvas 模拟实现电子彩票刮
- 仿Win10 UI界面(前端html模板)
- 永劫无间主题 html+css
- 登录html
- 游戏商城html模板(首页)
- 生日祝福html代码(带背景音乐)
- 基础html小米商城
- W3C html5 参考手册(教学资源免费)
- html5 2048小游戏
- oa html模板(基于Vue开发)
- 个人网站备案的HTML模板
- html旅游静态网站
- 简易京东网页HTML代码(HTMLamp;JS;)
- 有问必答项目 html源码
- html 塔防游戏runner
- html 二十一点
- 生日祝福html网页源码(特效很多)
- 时时彩网站 html模板(手机端 )
- HTML可视化面板
- 印象烘培 首页html源码
- H5彩票网站html代码
- 教育类网站html代码
- 人才招聘资讯博客HTML模板手机版自适
- 新浪手机新闻网站模板首页html源码
评论
共有 条评论