This is a quick question. How do I create a new document based on an existing template? I cant seem to find this info on the wiki, also if my new document is made up of other documents using the importnode does this cause the new document to lose its formatting from the template it should be attached too?
The procedure of creation of document based on existing template is pretty much the same as opening the existing document and saving it under different name. For example,
Document doc = new Document(Application.StartupPath + @"\template.dot");
Concerning your second question - you can actually choose whether you want to keep the existing formatting of the appended sections or use the destination document styles.
That can be done by using ImportFormatMode parameter of the Document.ImportNode method.
That is an expected behaviour. You can see the same thing when you append documents to template in MS Word. If you want your template to be just a source of styles and don’t want the content that is already in it then you need to remove the very first section of the resulting document by using Document.Sections[0].Remove.
Document audDoc = new Document(myDocs + “\” + “Auditdocs.dot”);
audDoc.Document.Sections[0].Remove();
But now no documents that are appended appear?? I take it this is
because all sections are removed and these sections are then appeneded
to the remove section?
I decided to try what the Wiki suggests
audDoc.Document.Sections.Clear;
Although this is slightly better I still get some pages prior to the appended information.
I can’t use this code because although it removes the pages it also
removes the headers and footers (as you are removing sections[0])
I do not wish to display the code here publically but perhaps I could
send you two dummy documents and you could write a simple demo for me
to work from?
I have attached two source documents. I would like to get 1.doc and
2.doc on the same page, with a header and footer using the template I
have provided earlier.
I would also like to see a demo where 1.doc and 2.doc are not on the
same page but on the same document, with header and footer using the
template.
If you could provide me with these two demos, I am sure I could apply the same methods to my actual code.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.