Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All ,

I have Created a datagridView with the Column Names First Name , Last Name , Address Line 1 , Address Line Three , Address Lien 4.

I am struggling to export this to a Word Document .The Mail Merge fields are the column titles.

How would I go about looping through each cell to then create a mail merge document?
Posted

1 solution

You are asking about how to loop through the datagrid view and then using the each grid view row value perform the mail merge.

to read the datagridview rows one by one

C#
foreach(DataGridViewRow row in dataGridView1.Rows)
{
    string myValue1 = (string)row.Cells[ColumnIndex1].Value;
    string myValue2 = (string)row.Cells[ColumnIndex2].Value;
}


To use the MsWord mail merge feature you must perform word automation by including the MsWord library into your project. follow the below link on how to perform word automation and mail merge

http://support.microsoft.com/kb/301659[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900