0

各文書のヘッダーとフッターを保持しながら、複数の Word 文書を結合したいと考えています。以下のコードはドキュメントをマージしていますが、ヘッダーとフッターもマージしています。

public static void Merge(List filesToMerge, string outputFilename)
{
    Application wordApplication = null;
    Document wordDocument = null;

    try
    {
        // Create a new Microsoft Word application object
        wordApplication = new Application();
        wordApplication.Visible = false;
        wordApplication.ScreenUpdating = false;

        // Create a new file based on our template
        object defaultTemplate = @"Normal.dotm";
        wordDocument = wordApplication.Documents.Add(ref defaultTemplate);

        // Make a Word selection object.
        Selection selection = wordApplication.Selection;

        // Loop thru each of the Word documents
        foreach (string file in filesToMerge)
        {
            // Insert the files to our template
            selection.InsertFile(file);
            object pageBreak = WdBreakType.wdSectionBreakNextPage;
            selection.InsertBreak(ref pageBreak);
        }

        // Save the document to it's output file.
        object outputFile = outputFilename;
        wordDocument.SaveAs(ref outputFile);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error while conversion. Details: " + ex);
    }
    finally
    {
        MSWordCleanup(wordApplication, wordDocument);
    }
}

とにかくそうすることがありますか?

4

1 に答える 1

0

次のトレーニング レッスンに取り組むことが役立つ場合があります

これで「自動化形式」の答えが得られるわけではありませんが、答えを理解するには十分かもしれません。

于 2012-06-12T15:42:58.393 に答える