471,896 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

Word Interop: Quickly Inserting HTML Files into Word

Hi, All:

I know how to insert files into a Word doc using C#. However, the program
I've written to do this runs much too slowly. The
"myObj".Application.Selection.InsertFile method executes at a snails pace.
Here are the detais:

I wrote a C# program that creates a 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).

As each file is inserted, the instance of Word takes a long time to complete
the insert (I've waited up to 5 minutes for some pages to finish inserting).

Can someone explain why the insert takes 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 that don't contain 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);
WordApp.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdNormalView;

//add sFile to word doc
//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)
Nov 16 '05 #1
0 1908

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jason Steeves | last post: by
56 posts views Thread by Richard Grene | last post: by
2 posts views Thread by Steve | last post: by
4 posts views Thread by fabrice | last post: by
reply views Thread by SergioT | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.