3

Microsoft Office Interop Assemblies(Office 2007)とASP.NET3.5を使用して複数のWord文書をマージするのに問題があります。ドキュメントをマージすることはできますが、フォーマットの一部(つまり、フォントと画像)が欠落しています。

現在のマージコードを以下に示します。

private void CombineDocuments() {
        object wdPageBreak = 7;
        object wdStory = 6;
        object oMissing = System.Reflection.Missing.Value;
        object oFalse = false;
        object oTrue = true;
        string fileDirectory = @"C:\documents\";

        Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document wDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        string[] wordFiles = Directory.GetFiles(fileDirectory, "*.doc");
        for (int i = 0; i < wordFiles.Length; i++) {
            string file = wordFiles[i];
            wDoc.Application.Selection.Range.InsertFile(file, ref oMissing, ref oMissing, ref oMissing, ref oFalse);
            wDoc.Application.Selection.Range.InsertBreak(ref wdPageBreak);
            wDoc.Application.Selection.EndKey(ref wdStory, ref oMissing);
        }
        string combineDocName = Path.Combine(fileDirectory, "Merged Document.doc");
        if (File.Exists(combineDocName))
            File.Delete(combineDocName);
        object combineDocNameObj = combineDocName;
        wDoc.SaveAs(ref combineDocNameObj, ref m_WordDocumentType, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    } 

これがどのように達成されるかは必ずしも気にしません。必要に応じてPDF経由で出力できます。フォーマットを引き継いでほしいだけです。

4

1 に答える 1

-1

ドキュメントを追加するときに、テンプレート名をスキップしているため、ut に形式がありません。

次のように見えるはずです

string defaultTemplate="your template name with full path"; 

また

デフォルトのテンプレート名

string defaultTemplate="Normal.dot";

wordApplication.Documents.Add(ref defaultTemplate,............

このリンクを参照として使用してください: http://devpinoy.org/blogs/keithrull/archive/2007/05/23/how-to-merge-multiple-microsoft-word-documents-in-c.aspx

于 2010-05-26T13:40:21.687 に答える