小鹿鹿鹿 2020-07-04 00:20 采纳率: 100%
浏览 451
已采纳

HTML页面内容转为带有格式的Word文档保存(Ueditor编辑器内的内容)

从网上找了这个方法,可以写成功文档,但是文档内容会乱码,请大神赐教

String uContent = “<html><p style="text-indent: 2em; text-align: center;"><span style="font-size: 20px;"><strong>标题</strong></span><br/></p><p style="text-indent: 2em;">我想要3个<em>苹果</em>。</p></html>;

byte b[] = uContent.getBytes("utf-8");
ByteArrayInputStream bais = new ByteArrayInputStream(b);
//生成Word文档
POIFSFileSystem poifs = new POIFSFileSystem();
 DirectoryEntry directory = poifs.getRoot();
 DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);//生成word
FileOutputStream ostream = new FileOutputStream(WordPath);
poifs.writeFilesystem(ostream);//把文档写到指定位置
 bais.close();
 ostream.close();

这是文档乱码的样子

图片说明

  • 写回答

1条回答 默认 最新

  • 暖酒与春风 2020-07-04 09:50
    关注

    byte b[] = uContent.getBytes("utf-8"); 换成gbk试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?