This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
↧
New Post: Image not inserted in resulted docx document.
↧
New Post: heading tag and font name changes are not applied to open xml document
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
↧
↧
New Post: Add section breaks in a document
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
↧
New Post: System.NullReferenceException occurred in DocumentFormat.OpenXml.dll
I am trying to use the source code but when running a simple test case it fails in HtmlConverter.cs line 89 in the if (mainPart.Document.Body == null)
A first chance exception of type 'System.NullReferenceException' occured in DocumentFormat.OpenXml.dll
Additional informatio: Object reference not set to an instance of an object.
If there is a handler for this exception, the program may be safely continued.
Does anyone get the same behaviour?
A first chance exception of type 'System.NullReferenceException' occured in DocumentFormat.OpenXml.dll
Additional informatio: Object reference not set to an instance of an object.
If there is a handler for this exception, the program may be safely continued.
Does anyone get the same behaviour?
↧
New Post: System.NullReferenceException occurred in DocumentFormat.OpenXml.dll
I'm pretty sure the MainDocumentPart argument you pass in the constructor of HtmlConverter is null.
Because the Document and the Body is created on the fly if they don't exist.
Because the Document and the Body is created on the fly if they don't exist.
↧
↧
New Post: Error when inserting HTML into Word table
I may be doing something wrong as I am just learning the Open XML SDK, but when I embed the HTML into a table in the Word document and then open the Word document I get this error:
"The file ... cannot be opened because there are problems with the contents. Ambiguous cell mapping encountered. Possible missing paragraph element. <p> elements are required before every </tc>.
The table and HTML appear fine when Word recovers the contents, but I need to get rid of this error so users don't see it.
This is what that snippet of my code looks like:
"The file ... cannot be opened because there are problems with the contents. Ambiguous cell mapping encountered. Possible missing paragraph element. <p> elements are required before every </tc>.
The table and HTML appear fine when Word recovers the contents, but I need to get rid of this error so users don't see it.
This is what that snippet of my code looks like:
tr = new TableRow();
tc = new TableCell();
MainDocumentPart mainPart = wordDocument.MainDocumentPart;
HtmlConverter converter = new HtmlConverter(mainPart);
IList<OpenXmlCompositeElement> paragraphs;
paragraphs = converter.Parse(htmlText);
for (int i = 0; i < paragraphs.Count; i++)
{
tc.Append(paragraphs[i]);
}
tc.Append(new TableCellProperties(new TableCellMargin(
new TopMargin { Type = TableWidthUnitValues.Dxa, Width = "72" },
new LeftMargin { Type = TableWidthUnitValues.Dxa, Width = "72" },
new RightMargin { Type = TableWidthUnitValues.Dxa, Width = "72" })));
tr.Append(tc);
table.Append(tr);
↧
New Post: Having issue for
Maybe, it's just me, but the "<hr>" tag is not rendering in the document. I tried "<hr />" and "<hr></hr>". Is anyone else having issue with this tag or is it just me? Thanks you for your help!
↧
New Post: Having issue for
Never mind, it works now, my apology.
↧
New Post: Background Image or absolute positioning
Hi, I have to create a docx document with image behind text or with some watermark image on every page. Is it possible?
Something like "background image" or "position: absolute" seem to not work.
Thanks!
Stefano
Something like "background image" or "position: absolute" seem to not work.
Thanks!
Stefano
↧
↧
New Post: List paragraph style not picked up
I read in a previous posts that the newer version keeps the styles such as headings and listparagraphs etc, but it does not.
can anyone suggest a fix.
In particular i am interested when having bullet points or numbered lists, when the converted docx document is created their style appears as normal not list paragraph and they are not indented like they should be. Also for the headings they don't get converted properly. I am reading html value from a rich text field in sharepoint and want to convert it into a word document and keep all the styling.
Any help is really appreciated.
thank you in advancce
can anyone suggest a fix.
In particular i am interested when having bullet points or numbered lists, when the converted docx document is created their style appears as normal not list paragraph and they are not indented like they should be. Also for the headings they don't get converted properly. I am reading html value from a rich text field in sharepoint and want to convert it into a word document and keep all the styling.
Any help is really appreciated.
thank you in advancce
↧
New Post: Error when inserting HTML into Word table
Maybe a bit late... but adding a table is a bit complicated in OpenXml.
I suggest you to embed your Html code with "<table><tr><td>" + yourHtml + "</tr></td></table>"
and lets Html2OpenXml handle the table for you
I suggest you to embed your Html code with "<table><tr><td>" + yourHtml + "</tr></td></table>"
and lets Html2OpenXml handle the table for you
↧
New Post: Problem with Image in docx file.
Hey, i just wanna use this library in my project but i have issue with images.
When im converting html around new MainDocument part in brand-new document everything seeem to be ok, but in my project i have template.
In this case i wanna insert converted HTML to my template using OpenXML. After open, i have no image, only border with alert "This image cannot currently be displayed".
Whats going on?
When im converting html around new MainDocument part in brand-new document everything seeem to be ok, but in my project i have template.
In this case i wanna insert converted HTML to my template using OpenXML. After open, i have no image, only border with alert "This image cannot currently be displayed".
Whats going on?
↧
New Post: Problem with Image in docx file.
Hi,
When the parser encounters images, it creates relations to "ImagePart". This is how works OpenXml.
I recommend you to use this library with the final MainDocumentPart that you targets, not working with a "temp" DocumentPart.
When the parser encounters images, it creates relations to "ImagePart". This is how works OpenXml.
I recommend you to use this library with the final MainDocumentPart that you targets, not working with a "temp" DocumentPart.
using (WordprocessingDocument package = WordprocessingDocument.Open(template, true)) { HtmlConverter converter = new HtmlConverter(package.MainDocumentPart); ... }
↧
↧
New Post: Apply Word style based on p class
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
↧
New Post: Apply Word style based on p class
can you please share how that worked for you
↧
New Post: Apply Word style based on p class
It's strange I never reply to this post because I have commited back in the source this change.
So syyad, there is 2 ways to do that:
1) use a predefined template with these style having the same name as the class attribute. It works for any "container" tag: span, div, p, pre, etc...
2) handle the StyleMissing event as you did and create the style on the fly. Here is an example
You can refer to the documentation for more explanation
So syyad, there is 2 ways to do that:
1) use a predefined template with these style having the same name as the class attribute. It works for any "container" tag: span, div, p, pre, etc...
2) handle the StyleMissing event as you did and create the style on the fly. Here is an example
You can refer to the documentation for more explanation
↧
New Post: Nested numbered lists
After checking the source code, I found a dirty workaround for the immediate document I am working with: using
That took care of the numbering formats, but there is still an issue for which I blame Word - lists continuing previous numbering globally in the document, instead of starting a new list.
Just thought I'd mention.
style="list-style-type:lower-roman"
in the 2nd level <ol>.That took care of the numbering formats, but there is still an issue for which I blame Word - lists continuing previous numbering globally in the document, instead of starting a new list.
Just thought I'd mention.
↧
↧
New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?
Just a simple question, are you trying to achieve a table of contents?
Because there is easier way :-)
If you want to use your own list instance style, I recommend you to define it by Word, then append the conversion into your document.
If you still want to perform it by code, take a look at NumberingListStyleCollection.cs (function InitNumberingIds) and copy this snippet to your program.
Update with your wished configuration (level 1 = LowerLetter for example).
Then, change your list instance to use this definition.
About your question related to "Set Number Value", I effectively use it to force restarting level to 1.
The key is StartOverrideNumberingValue() { Val = 1 } (see NumberingListStyleCollection.BeginList())
I think, I should add a way to let you push your own list definition.
Because there is easier way :-)
If you want to use your own list instance style, I recommend you to define it by Word, then append the conversion into your document.
If you still want to perform it by code, take a look at NumberingListStyleCollection.cs (function InitNumberingIds) and copy this snippet to your program.
Update with your wished configuration (level 1 = LowerLetter for example).
Then, change your list instance to use this definition.
About your question related to "Set Number Value", I effectively use it to force restarting level to 1.
The key is StartOverrideNumberingValue() { Val = 1 } (see NumberingListStyleCollection.BeginList())
I think, I should add a way to let you push your own list definition.
↧
New Post: Nested numbered lists
I think one of the critical things in word is defining your styles to use are in the template.
You need to either Program, import or manually create your styles in a doc or a XML file FIRST
html2openxml will apply the conversion from css class to word style, but it does not format the style, you need to do that yourself before you convert from html.
I use a predefined document that I then populate all the content controls with snipits of html.
But if I was creating new documents I would either open a blank doc with my styles or import the styles.xml & numbering.xml.
Use this to check your style are defined first:
converter.HtmlStyles.DefaultStyle = converter.HtmlStyles.GetStyle("MultilevelList");
You need to either Program, import or manually create your styles in a doc or a XML file FIRST
html2openxml will apply the conversion from css class to word style, but it does not format the style, you need to do that yourself before you convert from html.
I use a predefined document that I then populate all the content controls with snipits of html.
But if I was creating new documents I would either open a blank doc with my styles or import the styles.xml & numbering.xml.
Use this to check your style are defined first:
converter.HtmlStyles.DefaultStyle = converter.HtmlStyles.GetStyle("MultilevelList");
↧
New Post: Should H1 restart the numbering of H2 or I am doing something wrong in the template?
Not really building a TOC, just a document with 2-3 levels of heading with some plain text and nested lists after each of the headings.
I defined numbering in the template and it applied fine, except for one issue, which I isolated to Word itself: that 2nd level headings do not re-start numbering after the 1st level headers. When I simply add a few lines to a brand new Word document, based on Normal.dotx, and apply Heading 1 and Heading 2 styles, then Heading 2 numbering is not re-started after Heading 1. So it seems that Word itself is not restarting numbering.
That might be related to behaviour of the multilevel lists I mentioned in another thread: when using "list-style-type:lower-roman" the 2nd level listings are numbered continuously throughout the document as below:
I defined numbering in the template and it applied fine, except for one issue, which I isolated to Word itself: that 2nd level headings do not re-start numbering after the 1st level headers. When I simply add a few lines to a brand new Word document, based on Normal.dotx, and apply Heading 1 and Heading 2 styles, then Heading 2 numbering is not re-started after Heading 1. So it seems that Word itself is not restarting numbering.
That might be related to behaviour of the multilevel lists I mentioned in another thread: when using "list-style-type:lower-roman" the 2nd level listings are numbered continuously throughout the document as below:
1. List item 1
2. List Item 2
i. Nested 1
ii. Nested 2
3. List item 3
Some text
1. List Item 1
2. List Item 2
iii. Nested 1
iv. Nested 2
3. List item 3
but if I am not using "list-style-type", than the 2nd nested list is numbered just 1,2,3, which is a wrong format but correctly starting at 1.↧