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 Feb 24, 2017 8:30 pm

We create a main document. We have other documents that we modify and then append to the main document. Two of the documents are having their fonts change from Calibri to Times Roman. I have attached the main document. The last two documents in the main document are the documents where the font is changing. I have also attached the original copy of the 2 documents so you can see their font is Calibri. Below, is an example of how we are merging the documents.

Thanks for your help


Document oMainDocument = new Document();

Document oDocumentTemplate = new Document(strTemplateFile));
Document oDocument = oDocumentTemplate.Clone();
oDocument.Replace("#Test", "Test Data", true, true);

foreach (Section sec in oDocument.Sections)
{
oMainDocument.Sections.Add(sec.Clone());
}

oMainDocument.LastParagraph.AppendBreak(BreakType.PageBreak);

oDocument.SaveToFile(strFullFilename, FileFormat.Docx);

druchti
 
Posts: 8
Joined: Tue Aug 02, 2016 12:47 pm

Mon Feb 27, 2017 7:19 am

Dear druchti,

Thanks for your inquiry and sorry for late reply as weekend.
There are three files in attachment. In my understanding, you want to add the two files(Body Order Summary Form.dotx and Chassis Order Summary Form.dotx) into the main file(11024PrepPack.docx). But I got ArgumentException when loading the main file. I have posted this issue to our Dev team, we will inform you when it is fixed.

In addition, we checked the two .dotx files, and found the font Calibri is the default font in template file. I am afraid that the default font cannot be cloned into a new file. In this case, we suggest you set one .dotx file as target file, and then add the others files into it. The font will not be changed, here is sample code for your kind reference.
Code: Select all
            Document OriginalDoc1 = new Document();
            OriginalDoc1.LoadFromFile(@"F:\testing\Body Order Summary Form.dotx");

            Document TargetDoc = new Document();
            TargetDoc.LoadFromFile(@"F:\testing\Chassis Order Summary Form.dotx");
            foreach (Section sec in OriginalDoc1.Sections)
            {
                TargetDoc.Sections.Add(sec.Clone());
            }
            TargetDoc.SaveToFile("9877-2.docx", FileFormat.Docx);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Mar 01, 2017 1:57 pm

Thank you. That did the trick.

druchti
 
Posts: 8
Joined: Tue Aug 02, 2016 12:47 pm

Tue Mar 14, 2017 9:37 am

Dear druchti,

Thanks for waiting.
Gald to inform you that the ArgumentException when loading file(11024PrepPack.docx) has been fixed in Spire.Doc Pack(hot fix) Version:5.8.70, welcome to test it.
Looking forward to your feedback.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc