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.

Wed Nov 07, 2018 7:55 pm

Hello, I'm attempting to replace text in an original document with another temporary document. It is not retaining the font in the original document or from the temporary document. Both are Calibri 11. The result is Calibri 10. How can I retain the font? I'm using the 6.10.6 evaluation version.

Document destinationDoc = new Document();
destinationDoc.LoadFromFile(di + @"\Proposal.docx");
Document tempDocument = new Document();
tempDocument.LoadFromFile(di + @"\Temp.docx");

string searchLineOfBusiness = "###INSERT_GENERAL###";
destinationDoc.Replace(searchLineOfBusiness, tempDocument, false, true);

tholland
 
Posts: 22
Joined: Fri Dec 01, 2017 6:38 pm

Thu Nov 08, 2018 3:27 am

Hi,

I have reproduced the issue and logged it in our bug tracking system. Once there is any update for you, we will let you know. Sorry for the inconvenience caused.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Fri Nov 09, 2018 11:03 am

Hi,

After investigation, we found the cause of the issue. It is because that the default style will not be cloned when replacing, and you should clone the default style by yourself before replacing. Please refer to below code.
Code: Select all
    Document destinationDoc = new Document();
    Document tempDocument = new Document();
    destinationDoc .LoadFromFile(di + @ "\Proposal.docx");
    tempDocument .LoadFromFile(di + @"\Temp.docx");
    tempDocument .CloneDefaultStyleTo(destinationDoc );// clone the default style
    String searchLineOfBusiness = "###INSERT_GENERAL###";
    destinationDoc .Replace(searchLineOfBusiness , tempDocument , false, true);
    destinationDoc .SaveToFile(di + @"\Result.docx");
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Sun Nov 18, 2018 6:48 pm

Thank you. This seemed to replace the style for each page in the destination document and just not the section that was being replaced. We ended up creating a custom style in both the source and destination to retain the font.

tholland
 
Posts: 22
Joined: Fri Dec 01, 2017 6:38 pm

Mon Nov 19, 2018 9:07 am

Hi,

Thanks for your feedback.
Any question, feel free to contact us.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Return to Spire.Doc