1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
namespace ConsoleApplication2
{
class Program
{
private void openWithDataSource()
{
Object oFalse = false;
Object oTrue = false;
Object missing = System.Reflection.Missing.Value;
Application msWord = new Application();
msWord.Visible = true;
Document nvDoc = msWord.Documents.Add(ref missing, ref missing, ref missing, ref missing);
object fileName = @"C:\document.doc";
string dbName = @"C:\document.txt";
MailMerge mailMerge = nvDoc.MailMerge;
mailMerge.OpenDataSource(dbName, ref missing, ref missing, ref oTrue,
ref oFalse, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
msWord.DocumentBeforeClose += new ApplicationEvents4_DocumentBeforeCloseEventHandler(beforeClose);
}
static void Main(string[] args)
{
Program program = new Program();
program.openWithDataSource();
}
private void beforeClose(Document doc, ref bool Cancel)
{
Debug.WriteLine("on passe ici");
}
}
} |
Partager