html格式的文档转成word下载
2024-08-31 12:25:08
当我们前端使用ueditor插件来让用户输入数据,保存至数据库。在另一个地方需要打印用户输入的内容的时候可以用到。因为要将ueditor带格式保存下来保存的就是html格式的内容,后台转化如下:
@RequestMapping("ueditorPrintAction.do")
public void uePrint(HttpServletRequest request,HttpServletResponse response) throws IOException{
CivilParam param=new CivilParam();
param.setParamData(null);
CivilResult result=ueditorPrintService.queryContext(param);
map=(Map) result.getResultData();
//以上是通过pring dubbo来进行数据库查询
String htmlContent=map.get("content").toString();
//字符替换
htmlContent = htmlContent.replaceAll("`lt`", "<");
htmlContent = htmlContent.replaceAll("`gt`", ">");
htmlContent = htmlContent.replaceAll("`quot`", "\"");
htmlContent = htmlContent.replaceAll("`#39`", "'"); String content = "<html>"+htmlContent+"</html>";
//如果出现乱码getBytes传入编码参数
byte b[] = content.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
//输出文件 名
String name=map.get("name").toString();
//如何出现乱码getBytes传入编码参数
// HttpServletResponse response = getResponse();
response.setHeader("Content-Disposition",
"attachment;filename=" +
new String( (name + ".doc").getBytes(),
"iso-8859-1"));
response.setContentType("application/msword");
OutputStream ostream = response.getOutputStream();
poifs.writeFilesystem(ostream);
//return JSON;
}
最新文章
- Linux内核补丁升级
- Windows Server 2003开机自动启动MySQL服务设置方法
- SQL Server 2008R2 禁用远程连接
- Content Providers
- DUBBO安装配置注意事项
- $(document).ready(); $().ready(); $()
- 升级python的sqlite库版本
- Spark1.5.1的安装与部署 每一步详细测试截图
- [转]解决get方法传递URL参数中文乱码问题
- cocos2d之Box2D详细说明 鼠标联合实现
- STM32F4中USB与PC双向通信
- 购物网站首页(学习ING)
- 如何使用Shiro
- JS闭包与JS函数
- 基于Winform框架DataGridView控件的SqlServer数据库查询展示功能的实现
- Ansible 进阶技巧
- Python threading 单线程 timer重复调用函数
- 富文本(wangEditor框架)的使用教程
- spring---aop(9)---Spring AOP中引入增强
- Vue项目中将table组件导出Excel表格以及打印页面内容