Click here to Skip to main content
11,715,022 members (64,819 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# DataGrid Word
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 10-Dec-12 0:28am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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[^]

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 530
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 115
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100