473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Word Interop: Quickly Inserting HTML Files into Word

ajk
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);
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)
}
Nov 16 '05 #1
0 1990

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Helene Day | last post by:
I am trying to access the Word Objects from a .NET project. I have some sample from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/WordObject.asp and I...
6
by: Jason Steeves | last post by:
I am hoping someone can tell me how, or point me in the right direction for the following problem. I need to have word open a specified file, .mht, as a plug-in inside of IE so that I can edit...
1
by: ajk | last post by:
. 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...
0
by: ajk | last post by:
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...
56
by: Richard Grene | last post by:
using Word automation from vb.net how can I get to the bottom of the document? Thanks, Richard
2
by: Steve | last post by:
I'm using Visual Studio .NET (not 2003), and am developing a class that works with Word theough the Office PIAs (Interop). I can open word and do things with it programatically, but I can't close...
5
by: Bob | last post by:
I'm getting error 8007007e when executing the following code. Dim word As New Microsoft.Office.Interop.Word.Application Dim doc As Microsoft.Office.Interop.Word.Document doc =...
4
by: fabrice | last post by:
Hello I m working with Framework 1.1. I d like to interact with word files (.doc or .dot) from the server. But Neither office or word are installed on it. There is a way for manipulating word...
0
by: SergioT | last post by:
hi I m getting an error when I run my application on the server, that error doesn't ocur when I run the application on the development computer the error is:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.