java根据html生成word文档,Java之HTML富文本导出WORD(不含图片) |
您所在的位置:网站首页 › 富文本生成word › java根据html生成word文档,Java之HTML富文本导出WORD(不含图片) |
一、需求: 我们在使用富文本编辑器来编辑文本的时候,文本会自带HTML的标签比如 等来修饰字体样式。 比如ueditor、kindeditor等富文本编辑器。 那么,我们如何将富文本编辑器里的内容导出到word文档里? 二、思路: word文档是可以识别完整的html页面的,所以我们需要将首尾缺失的标签补齐。 1.首先我们需要建立一个word导出的工具类: /** * html 导出 word 工具类 * @author zhangxiang * */ public class WordUtil { public static void exportWord(HttpServletRequest request, HttpServletResponse response, String content, String fileName) throws Exception { byte b[] = content.getBytes("GBK"); //这里是必须要设置编码的,不然导出中文就会乱码。 ByteArrayInputStream bais = new ByteArrayInputStream(b);//将字节数组包装到流中 POIFSFileSystem poifs = new POIFSFileSystem(); DirectoryEntry directory = poifs.getRoot(); DocumentEntry documentEntry = directory.createDocument("WordDocument& |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |