Copy MathType equation from one doc to another

I use the following code to test:

Document doc = new Document("input.docx");
Paragraph p = (Paragraph) doc.Sections[0].Body.ChildNodes[0];
Shape shape = (Shape) p.ChildNodes[0];
string fileName = "ole_object.bin"
shape.OleFormat.Save(fileName);

Document newDoc = new Document("template.docx");
DocumentBuilder builder = new DocumentBuilder(newDoc);
builder.MoveToDocumentEnd();
Shape newShape = builder.InsertOleObject(fileName, false, false, shape.ImageData.ToImage());
newShape.OleFormat.ProgId = shape.OleFormat.ProgId;
newDoc.Save("output.docx"));

However, in the generated “output.docx”, when double clicking the equation, it cannot be opened by MathType as in the “input.docx”.

The related word docs are attached.

Hi Jesse,

Thanks for your inquiry. You can use the following code to import this equation to another Document:

Document doc = new Document(MyDir + @"input.docx");
Paragraph p = (Paragraph) doc.Sections[0].Body.ChildNodes[0];
Shape shape = (Shape) p.ChildNodes[2];
Document newDoc = new Document(MyDir + @"template.docx");
DocumentBuilder builder = new DocumentBuilder(newDoc);
builder.MoveToDocumentEnd();
Shape importedNode = (Shape) newDoc.ImportNode(shape, true);
builder.InsertNode(importedNode);
newDoc.Save(MyDir + @"output.docx");

I hope, this helps.

Best regards,

Thanks for your reply.

Is it possible to save the equation data to a data file or in the database, and then restore it some other time and insert to another doc?

Hi Jesse,

Thanks for your inquiry. Yes, this is possible. You can import equation into another empty ‘Document’ object and save Word document to database for further usage.

Best regards,