Mail Merge or Search and Replace for Equations in Word Documents?

I am working on a functional requirement to perform a search and replace for special text in a word document that contain equations in addition to the normal text elements. 
I find that while the merge fields themselves work fine, if there is a merge field in an equation the processing immediately fails and throws the Exception below.  I have included a small example document to demonstrate this behavior. 

Is there a  working solution to replacing values in equations ? Is this expected behavior? it seems that the interface for iterating through the equations themselves is clunky and would not work well when encountering a wide variety of complexity in equations.

Exception

Object reference not set to an instance of an object.

Source

Syncfusion.DocIO.Base

StackTrace

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.AddToParagraph(ParagraphItem item, ParagraphItemCollection paragraphItems)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.InitFieldMarkBegin(ParagraphItemCollection paraItems)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseRunValues(XmlReader reader, ParagraphItemCollection paraItems, IOfficeMathRunElement mathParaItem, Boolean isMappedPictureContentControl)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseRun(XmlReader reader, ParagraphItemCollection paraItems, IOfficeMathRunElement mathParaItem, Boolean isAlreadyChecked, XmlNodeType nodeType, Boolean isMappedPictureContentControl)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseMathRun(XmlReader reader, IOfficeMathRunElement mathParaItem)

   at Syncfusion.Office.MathMLParser.ParseMath(XmlReader reader, OfficeMath officeMath)

   at Syncfusion.Office.MathMLParser.ParseMathPara(XmlReader reader, IOfficeMathParagraph mathPara, DocumentParser documentParser)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseParagraphItems(XmlReader reader, ParagraphItemCollection paraItems, String endnode, IOfficeMathRunElement mathRunElement, Boolean isMappedPictureContentControl)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseBody(XmlReader reader, IEntity entity, Boolean isRunElementTextBody, Boolean isFromDocument, Boolean isMappedPictureContentControl)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseDocument(Stream stream)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.ParseDocument(Package wordPackage)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.Read(WordDocument document, Boolean isFlatOPC)

   at Syncfusion.DocIO.DLS.Convertors.DocxParser.Read(String fileName, WordDocument document)

   at Syncfusion.DocIO.DLS.WordDocument.OpenDocx(String fileName)

   at Syncfusion.DocIO.DLS.WordDocument.OpenInternal(String fileName, FormatType formatType, String password)

   at Audit_Report_Generator.AuditReportGenerator.GenerateReport(String fileName, String inputParameterJSON) in [file location]

TargetSite

{Void AddToParagraph(Syncfusion.DocIO.DLS.ParagraphItem, Syncfusion.DocIO.DLS.ParagraphItemCollection)}
System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}



Attachment: mailmergeequationsample_fc69b8ce.zip

3 Replies

SB Suriya Balamurugan Syncfusion Team July 21, 2022 09:50 AM UTC

Hi John,

We have reproduced the reported problem with “NullReferenceException while opening the given Word document” in our end, and we suspect it to be a defect. We will validate this issue and update you with more details on 25th July 2022.

Regarding - Is there a working solution to replacing values in equations? Is this expected behavior?
You can add or modify the text and formatting of existing mathematical equation in Word document.

Please refer our online demo sample link to modify the existing equation in Word document,
https://ej2.syncfusion.com/aspnetmvc/Word/EditEquation#/fluent

Please refer our UG documentation link to modify the existing equation in Word document,
https://help.syncfusion.com/file-formats/docio/working-with-mathematical-equation#modify-existing-equation

Regards,
Suriya Balamurugan.



AN Anto Nihil Sahaya Raj Syncfusion Team July 25, 2022 05:00 PM UTC

Hi John,

At now, we have internally fixed the exception while opening and saving document with field inside MathML.

After fixing internally, we are facing problems while updating fields and also executing mail merge for merge fields. We have found it need some deep analyzation and also takes more amount of time to find the approach to handle this. Also, it will take some more amount of time to handle mail merge functionality for fields inside MathML along with our existing priority plans.

So, it will be more helpful if you share your exact requirements. We will check on that direction as first priority and consider your requirement as first goal in our analyzation work.

Could you please share what you planned to do (end requirement of application) after opening document. If possible, share expected output document.

Based on your requirement, we will check and share any feasibility solution to achieve it.

At now, we have confirmed that reported issue withNullReferenceException throws while opening the DOCX document with MathML” is a defect and we have logged a defect report. We will include the fix for this defect in our weekly NuGet release which is estimated to be available on 16th August 2022.

The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/36585/nullreferenceexception-throws-while-opening-the-docx-document-with-mathml

Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”


Regards,
Anto Nihil S



AN Anto Nihil Sahaya Raj Syncfusion Team August 16, 2022 01:39 PM UTC

Hi John,

As promised earlier, we have included the fix for the reported issue with “NullReferenceException throws while opening the DOCX document with MathML” in our latest weekly NuGet release (v20.2.0.44).


Please use the below link to download our latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.DocIO.AspNet.Mvc5/20.2.0.44

The status of this bug task can be tracked through the below link:
https://www.syncfusion.com/feedback/36585/nullreferenceexception-throws-while-opening-the-docx-document-with-mathml

Note: We will include this fix in our 2022 Volume 3 Main release which will be available in end of September 2022.

Regards,
Anto Nihil S


Loader.
Up arrow icon