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.

Fri Jun 12, 2020 8:42 am

I see an example in the document that I can copy Word document to a new Word document, but Now I want to replace the content in the new document with the copied Word document. For example, I want to replace ${content} in the new document with the copied Word document. How can I achieve this function?

sailooxox
 
Posts: 1
Joined: Fri Jun 12, 2020 8:30 am

Fri Jun 12, 2020 10:21 am

Hello,

Thanks for your inquiry.
Please refer to the following code, and I attached my input files and output file for your reference. If there is any question, just feel free to write back.
Code: Select all
        Document template = new Document();
        template.loadFromFile("Template.docx");

        IDocument replaceDoc = new Document();
        replaceDoc.loadFromFile("Content.docx");

        // Replace specified text with the other document
        template.replace("${content}", replaceDoc, false, true);

        template.saveToFile("Output.docx", FileFormat.Docx);


Sincerely,
Rachel
E-iceblue support team
User avatar

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

Thu Jun 18, 2020 10:08 am

Hello,

Hope you are doing well.
Have you tested my code? Could you please give us some feedback at your convenience?

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Return to Spire.Doc