Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问可以解析html标签吗? #219

Open
zixiawallace opened this issue Apr 23, 2019 · 6 comments
Open

请问可以解析html标签吗? #219

zixiawallace opened this issue Apr 23, 2019 · 6 comments

Comments

@zixiawallace
Copy link

zixiawallace commented Apr 23, 2019

Sayi您好:
现在这版本貌似不支持html的标签解析,比如p标签,u 标签,sup 标签等。如果内容里面包含html格式,则生成的word也是带有这些标签无法解析的。
另外,比如一个{{content}},它的值是“巴拉巴拉巴拉 u 下划线 /u "这种,我看通过Style设置的是完整的content的值,而不是'u'标签内的值,请问这种怎么处理呢?

@Sayi
Copy link
Owner

Sayi commented Apr 24, 2019

你好,暂时不支持解析,但的确是个好想法

@LuciferWeidy
Copy link

我在网上找了一个解析html内容的插件,不知道是否需要。

@xuwangcheng14
Copy link

我在网上找了一个解析html内容的插件,不知道是否需要。

请问可否共享呢?目前自己解析的,感觉会有问题。有完善的插件最好。

@songlai
Copy link

songlai commented Nov 24, 2020

找到一种结果很完美的解决办法。
把富文本的地方当成引入外部word,如{{+html}}
然后定义变量的时候
param.put("html", new DocxRenderData(此处是一个由HTML转换为word的InputStream))
InputStream 我是用了 AsposeWord 转换的:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml(html);
ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.save(out, SaveFormat.DOCX);

最后把 OutputStream 转为 InputStream 供 new DocxRenderData() 使用。
效果完美!当然了,AsposeWord 是收费的。

@799452017
Copy link

找到一种结果很完美的解决办法。
把富文本的地方当成引入外部word,如{{+html}}
然后定义变量的时候
param.put("html", new DocxRenderData(此处是一个由HTML转换为word的InputStream))
InputStream 我是用了 AsposeWord 转换的:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml(html);
ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.save(out, SaveFormat.DOCX);

最后把 OutputStream 转为 InputStream 供 new DocxRenderData() 使用。
效果完美!当然了,AsposeWord 是收费的。

我搞不懂转为inputStream后怎么使用

@draco1023
Copy link

写了个插件,因为引入了一些依赖,不适于通过pull request提交,作为一个扩展包。
地址:https://github.com/draco1023/poi-tl-ext
有兴趣的可以试试,通过富文本编辑器得到的html大部分效果都实现了,部分特性后续完善,欢迎交流反馈。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants