Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Feb 20, 2020 9:47 am

Hello Spire,

My task: Convert a html/docx document to a docx/html document. I found in Spire help how's that done and implemented it successfully. My problem though, is that upon html -> doc conversion, I need to process some custom html tags and to produce from them some corresponding word doc objects. In particular, I need to insert "merge fields" in the html document and upon conversion to produce the corresponding merge fields in the resulting word document.

Questions:
1. Is there a native Spire way to achieve the above stated problem by providing some specific metadata (tags, comments, etc.) in the html, which the Spire convertor takes into account and produces a doc file with merge fields.

!!!IMPORTANT!!! I run the following experiment: I created a doc file with a merge field by using MS Word. Then I saved it as an html. The merge field was serialized in the html document as following:

<!--[if supportFields]><span style='mso-element:field-begin'></span><span
style='mso-spacerun:yes'> </span>MERGEFIELD FirstName <span style='mso-element:
field-separator'></span><![endif]--><span style='mso-no-proof:yes'>«FirstName»</span><!--[if supportFields]><span
style='mso-no-proof:yes'><span style='mso-element:field-end'></span></span><![endif]-->

Then I opened the html file with MS Word and converted it back to docx. In the newly created docx file, the merge field was restored successfully by the metadata provided in the comments in the html document. I rerun the same procedure programmatically by using Spire.Doc assembly. However, after the html -> doc conversion all merge field comments were lost.

2. If Spire Doc convertor has no support for converting merge fields in both directions (docx -> html, html -> doc), is there some alternative means for me as a developer to intercept the Spire conversion procedure and plug in my own code for custom converting particular doc objects/html tags.

Looking forward to hear from you!

Best Regards
Ivan

Ivanvvv
 
Posts: 4
Joined: Tue Apr 21, 2015 1:53 pm

Thu Feb 20, 2020 10:59 am

Hello,

Thanks for your iquiry.
I indeed noticed that using our product to convert .docx file containing the merge field to html, and then convert it back to .docx format, the merge field cannot be restored like in Microsoft Word. This issue has been posted to our Dev team with the ticket SPIREDOC-3941 for further investigation. If there is any update, we will let you know.
Apologize for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Feb 20, 2020 11:25 am

Hello Rachel,

Thanks for your quick reply!
When approximately could I expect any update from the Dev team?
Meanwhile, could you please answer my second question?

Thanks
Ivan

Ivanvvv
 
Posts: 4
Joined: Tue Apr 21, 2015 1:53 pm

Fri Feb 21, 2020 7:45 am

Hello,

Thanks for your response.
I got information from our Dev team that our product could support converting merge fields in both directions (docx to html and html to docx), but it may take a long time due to its complexity. Sorry at this moment we can't tell you an estimated time on it. Anyway, we will keep you informed once there is any update.
Thus, as for the second issue you mentioned, do you still need an alternative solution? If you still need it, to help us look into it better, please provide more detailed information about your needs, such as some input files and your desired output.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Feb 21, 2020 9:39 am

Hello Rachel,

Thank you for your update!

My second question is a request for a workaround. Since there is no support for conversion of merge fields, my only option is to find a workaround to achieve my requirements. One possibility would be if there are some events/hook points, which I could handle during the conversion process. This would allow me to alter your conversion algorithm and add the missing functionality. For example:

Document document = new Document();
doc.LoadFromFile("[Path to docx file]", FileFormat.Docx);
//todo: attach to some event in which I have control over the word element (merge field, paragraph, etc.) which is being currently converted
doc.SaveToFile("[Path to html file]", FileFormat.Html);

//The following is just a pseudo code
onConvertingElement(DocElement el)
{
if (el.Type == "MergedField")
{
//perform my custom conversion
//for example here I could generate a custom html tag like this: <mergefield>FirstName</mergefield>
}
}

Thank you for your collaboration!

Regards
Ivan

Ivanvvv
 
Posts: 4
Joined: Tue Apr 21, 2015 1:53 pm

Fri Feb 21, 2020 10:25 am

Hello,

Thanks for your feedback.
Sorry at present our product doesn't support the function you mentioned as alternative solution. Controlling the conversion process of docx to html is very complicated and it is difficult to achieve. I am afraid the best solution is waiting for the fix of the issue with the ticket SPIREDOC-3941.
Thanks for your understanding and apologize for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Feb 21, 2020 2:55 pm

Hello Rachel,

Thanks for your investigation.
Could you please hint me where could I observe the status of SPIREDOC-3941?

Regards
Ivan

Ivanvvv
 
Posts: 4
Joined: Tue Apr 21, 2015 1:53 pm

Mon Feb 24, 2020 2:00 am

Hello,

Sorry for the late reply as weekend.
Our bug tracking system is unavailable to customers at present, sorry there is no way for you to observe the status of your issue. If there is any update on the issue SPIREDOC-3941, I will inform you on this post. Thanks for your understanding.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc