Hello,
Thanks for your response.
According to the code you shared, you didn't AppendText or AppendHTML in the paragraph with the "standard" styles font-size
set to 10pt, but add a new section and append content in a new paragraph. I'm a little confused. When I try to appendText and appendHTML in the existing two paragraphs with the font size in your template document, I found that if I apply the style after the appendHTML operation, the style can't be applied successfully. But if I apply the style before appendHTML, the style can be applied. I got the explanation from our dev team as below. When parsing the html without any format setting, we will give the html content a default font format in the inner operation, here for div tag, it is 10pt as default. If there's already any style before the position where you append the html, it will continue apply the style before, otherwise it will apply the html's default format.Considering this, if you want to apply the format in the style, make sure there's already any style, that is, appy the style before appending the html.
Also, you were wondering the why the size(val=10) was written to the xml when appendHTML. First, this value is from the style, the font size 5 you set in the document will be parsed to 10. And when doing the appendHTML, we will set the format in the style as the current character format, so it write to the xml.
Below is the testing code for the first point.
- Code: Select all
Document doc1 = new Document();
doc1.LoadFromFile(@"C:\Users\Administrator\Desktop\Documents\Template.docx");
ParagraphStyle style = new ParagraphStyle(doc1);
style.CharacterFormat.FontSize = 5;
style.Name = "MyStyle";
doc1.Styles.Add(style);
Paragraph p = doc1.Sections[0].Paragraphs[1];
p.AppendText("Test appendText method");
p.ApplyStyle(style.Name);
Paragraph p1 = doc1.Sections[0].Paragraphs[2];
p1.ApplyStyle(style.Name);
p1.AppendHTML("<div>Test appendHTML method</div>");
doc1.SaveToFile("AppendHTML.docx");
Hope I make it clear.
Sincerely,
Jane
E-iceblue support team