There has to be a better method than what I'm doing to merge two word documents. I'm hoping someone can point me towards that method.
I'll show the code in a bit here, but first an explanation. I have an existing Word.Document, this code is inside the class that is responsible for creating it. I'm appending another document to the end of the current document. My basic method of accomplishing this is to physically open the "other" (passed as a parameter) word document, grab the text, and then place that text at the end of my current document.
Now, the code.
It feels very inefficient to have to actually open the Word Document, pull the data, and then close it. When you also consider I'll be doing this a few times (at most maybe 10, but still) you can see why I'd hope to make the process as quick as possible.
Well, thanks for any help. I try to stay humble, so feel free to criticize any other errors you feel are in the code and I'll try not to be too defensive.
I'll show the code in a bit here, but first an explanation. I have an existing Word.Document, this code is inside the class that is responsible for creating it. I'm appending another document to the end of the current document. My basic method of accomplishing this is to physically open the "other" (passed as a parameter) word document, grab the text, and then place that text at the end of my current document.
Now, the code.
Code:
/// <summary>
/// Appends the specified document to the end of the current document
/// </summary>
/// <param name="FilePath"></param>
public void AppendDocument(string FilePath)
{
object missing = System.Reflection.Missing.Value;
object fileToOpen = (object) FilePath;
object FALSE = (object) false;
object start = 0;
object end = toMerge.Characters.Count;
Word.Document toMerge = _WAPP.Documents.Open(ref fileToOpen, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
// Select all Text in the passed Document, inserts it into this document,
// then closes the document
Word.Range allText = toMerge.Range(ref start, ref end);
this.InsertParagraph(allText.Text);
toMerge.Close(ref FALSE, ref missing, ref missing);
toMerge = null;
}
It feels very inefficient to have to actually open the Word Document, pull the data, and then close it. When you also consider I'll be doing this a few times (at most maybe 10, but still) you can see why I'd hope to make the process as quick as possible.
Well, thanks for any help. I try to stay humble, so feel free to criticize any other errors you feel are in the code and I'll try not to be too defensive.