akilgore

akilgore

  • NA
  • 1
  • 0

Quickly Inserting Html Files into New Word Doc

Apr 8 2004 9:36 PM
I'd like to know if there is a way to insert an HTML file into a new Word doc and have Word process it quickly. I wrote a C# program that creates the new Word doc and then loops through a list of HTML files to insert them into the new doc (sample code below). The purpose of the program is to make one Word doc out of all of these Html files (for archival purposes). Unfortunately, as each file is inserted, my instance of Word takes a long time to complete the insert (I've waited up to 5 minutes for some pages to finish inserting). The time seems to increase exponentially. I am using VS.NET 2003, but am forced to work with Word 2000 (because of legacy issues). I don't understand why it is taking so long. At first I thought it was graphic sizes (some HTML files have .jpg or .gif files in them as big as 58kb). But Word even inserts the Html files without graphics fairly slowly. If someone knows that I am doing wrong or knows of a more efficient way to accomplish this task, I'd appreciate hearing about it. Thanks in advance for any help you all provide. Sample code follows: //set stub objects (left out for brevity) //make word app and optimize Word.ApplicationClass WordApp = new Word.ApplicationClass(); WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; WordApp.Visible = false; //make word doc and optimize wrdDoc = WordApp.Documents.Add(ref template, ref newTemplate, ref docType, ref isVisible); wrdDoc.Activate(); WordApp.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdNormalView; //add sFile to word doc try { //insert file into wrdDoc wrdDoc.Application.Selection.InsertFile(sFile, ref docrange, ref conversions, ref links, ref attaches); //insert pagebreak wrdDoc.Application.Selection.InsertBreak(ref breaktype); } catch (System.Exception e) { //error trapping (not included for brevity) }