fwkb wrote:
i can know missing styles by using
converter.HtmlStyles.StyleMissing += (s, e) =>
}
i want to understand how to add the missing styles to word doc
I was able to do this by making a small addition to ProcessParagraph in HtmlConverter.ProcessTag.cs Here is what it looks like now: private void ProcessParagraph(HtmlEnumerator en) { CompleteCurrentParagraph(); AddParagraph(currentParagraph = htmlStyles.Paragraph.NewParagraph()); // Respect this order: this is the way the browsers apply them String attrValue = en.StyleAttributes["text-align"]; if (attrValue == null) attrValue = en.Attributes["align"]; if (attrValue != null) { JustificationValues? align = ConverterUtility.FormatParagraphAlign(attrValue); if (align.HasValue) { currentParagraph.InsertInProperties(new Justification { Val = align }); } } //start of my addition string classValue = en.Attributes["class"]; if (classValue != null) { currentParagraph.InsertInProperties(new ParagraphStyleId { Val = classValue }); } //end of my addition List<OpenXmlElement> styleAttributes = new List<OpenXmlElement>(); bool newParagraph = ProcessContainerAttributes(en, styleAttributes); if (styleAttributes.Count > 0) htmlStyles.Runs.BeginTag(en.CurrentTag, styleAttributes.ToArray()); if (newParagraph) { AlternateProcessHtmlChunks(en, "</p>"); CompleteCurrentParagraph(); AddParagraph(currentParagraph = htmlStyles.Paragraph.NewParagraph()); } } You need to make sure your base Word document has styles defined that use the exact same names as the classes. E.g. If you have something in your html with a class of "blue" you need to make sure you have a Word style in your base doc called "blue" (case sensitive). Otherwise no style is applied or the default style is applied. I have not tested this extensively but it seems to do the trick for me. I don't know how to check code back in to codeplex but anyone else can feel free to do so if it is useful.what do you mean by add styles to base word document, i have all my styles in html but how to make them work in doc.
i can know missing styles by using
converter.HtmlStyles.StyleMissing += (s, e) =>
{
missingStyles.Add(e.Name);}
i want to understand how to add the missing styles to word doc