wrdMailMerge = wrdDoc.MailMerge;
CreateMailMergeDataFile();
wrdMailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
object wdFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
Object fileName = "D:\\test.doc";
wrdDoc.SaveAs(ref fileName, 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, ref oMissing);
wrdDoc.Saved = true;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
wrdMailMerge = null;
wrdDoc = null;
wrdApp = null;
private void CreateMailMergeDataFile()
{
Microsoft.Office.Interop.Word._Document oDataDoc;
Object oName = "D:\\DataDoc.doc";
Object oHeader = "FirstName, LastName, Address, CityStateZip";
wrdDoc.MailMerge.CreateDataSource(ref oName, ref oMissing,
ref oMissing, ref oHeader, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
oDataDoc = wrdApp.Documents.Open(ref oName, 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, ref oMissing);
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblMailMerge", con);
SqlDataReader dr1;
dr1 = cmd.ExecuteReader();
int nR = 2;
while (dr1.Read())
{
FillRow(oDataDoc, nR++, dr1.GetString(1), dr1.GetString(2), dr1.GetString(3), dr1.GetString(4));
oDataDoc.Tables[1].Rows.Add(ref oMissing);
}
dr1.Close();
oDataDoc.Tables[1].Rows.Last.Delete();
oDataDoc.Save();
oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);
}
private void FillRow(_Document oDoc, int Row, string p_3, string p_4, string p_5, string p_6)
{
oDoc.Tables[1].Cell(Row, 1).Range.InsertAfter(p_3);
oDoc.Tables[1].Cell(Row, 2).Range.InsertAfter(p_4);
oDoc.Tables[1].Cell(Row, 3).Range.InsertAfter(p_5);
oDoc.Tables[1].Cell(Row, 4).Range.InsertAfter(p_6);
implemented.");
}
//throw new Exception("The method or operation is not implemented.");
}-----------------------
HOW TO SAVE THESE MERGED FILE.....pls Help......