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

Insert html to Word,html forrmat is #85

Closed
Wang0310 opened this issue Jun 27, 2022 · 9 comments
Closed

Insert html to Word,html forrmat is #85

Wang0310 opened this issue Jun 27, 2022 · 9 comments

Comments

@Wang0310
Copy link

I want to convert HTML to doc format, but I find that the style doesn't work, including setting the line spacing of paragraphs
code example:
image

but in fact:
image

@Wang0310
Copy link
Author

Sorry, the character format I wrote is wrong because it is not centered, but a lot of things in the HTML content do not take effect。
image
image
How should I write this style without right alignment as in the text?

@WEIQ311
Copy link

WEIQ311 commented Jun 27, 2022 via email

@WEIQ311
Copy link

WEIQ311 commented Jun 27, 2022

DocumentBuilder builder = new DocumentBuilder();
ParagraphFormat paragraphFormat = builder.getParagraphFormat();
paragraphFormat.setLineSpacingRule(LineSpacingRule.MULTIPLE);
paragraphFormat.setLineSpacing(24);
builder.writeln("word测试类型");
builder.writeln(LocalDateTime.now().toString());
builder.insertHtml("<a href='https://wwww.baid.com' _target='blank'>百度一下,都知道</a>");
builder.insertHtml("<p style='text-align:center;color:red;background-color:gray;'>文字居中显示</p>");
Document document = builder.getDocument();
document.save("./logs/test.docx");`

@Wang0310
Copy link
Author

是不是多了层" | | 魏强 | | @.*** |

---- Replied Message ---- | From | @.> | | Date | 06/27/2022 12:39 | | To | @.> | | Cc | @.> | | Subject | [aspose-words/Aspose.Words-for-Java] Insert html to Word,html forrmat is (Issue #85) | I want to convert HTML to doc format, but I find that the style doesn't work, including setting the line spacing of paragraphs code example: but in fact: — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>

嗯嗯,这个问题时多了一层。 已经找到原因了,现在第二个问题感觉不知道怎么设置,有些标签样式不生效了

@Wang0310
Copy link
Author

Wang0310 commented Jun 27, 2022

@WEIQ311
老哥好,你这个我试了下,跟我现在是一样的。我可能没有说清楚我的问题,我是有个业务场景会生成一段html页面,设置了一些样式,如附件里面的内容,我读取内容后插入生成word时,遇到的两个问题
1、配置的行距是不起作用,都是一个默认的行距,设置大小无效
2、有一些标签设置的样式,比如有个时间是靠右对齐,但生成word后不生效,想知道是怎么提出,替换标签还是有什么配置项是可以解决这个问题。
image

https://res.hwazhan.com/bg/upload/files/2022/6/1656329823006.txt?attname=html5.txt

@AlexNosk
Copy link

@Wang0310 @WEIQ311 The problem is that HTML document and MS Word document has quite different object model. And it is impossible to guaranty 100% fidelity after converting one to another. You can learn more about feature supported upon loading HTML from Aspose.Words documentation.

In your case, you can achieve what you need using table with two cells in your HTML.

@Wang0310
Copy link
Author

@AlexNosk ok, but I have another question. why can't the program set line spacing in HTML content take effect.

@AlexNosk
Copy link

@Wang0310 line-height style attribute corresponds Line Spacing in MS Word document. Aspose.Words take this attribute in account:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<p style=\"line-height:20pt;\">test</p><p style=\"line-height:20pt;\">test</p>");
doc.save("C:\\Temp\\out.docx");

image

@Wang0310
Copy link
Author

@AlexNosk OK, I see. thank you very much.

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

No branches or pull requests

3 participants