c# - Merge Multiple Word Documents while Preserving Headers - .Net Office Automation -
i want merge multiple word documents while preserving header , footer of each document. below code merging documents merges header , footer well:
public static void merge(list filestomerge, string outputfilename) { application wordapplication = null; document worddocument = null; try { // create new microsoft word application object wordapplication = new application(); wordapplication.visible = false; wordapplication.screenupdating = false; // create new file based on our template object defaulttemplate = @"normal.dotm"; worddocument = wordapplication.documents.add(ref defaulttemplate); // make word selection object. selection selection = wordapplication.selection; // loop thru each of word documents foreach (string file in filestomerge) { // insert files our template selection.insertfile(file); object pagebreak = wdbreaktype.wdsectionbreaknextpage; selection.insertbreak(ref pagebreak); } // save document it's output file. object outputfile = outputfilename; worddocument.saveas(ref outputfile); } catch (exception ex) { console.writeline("error while conversion. details: " + ex); } { mswordcleanup(wordapplication, worddocument); } }
is there anyway so?
it might helpful work through these training lessons: http://office.microsoft.com/en-us/word-help/headers-and-footers-from-basic-to-elaborate-rz001021662.aspx
while won't give answer in "automation form", might enough figure out answer.
Comments
Post a Comment