|
-
Jun 13th, 2011, 12:14 PM
#7
Thread Starter
New Member
Re: Export data from datagrid to MS Word using vb.net
I managed to copy it over but I feel that it was rather by luck as I saw a code where it exports data from datagrid to Excel and I just referred to the code.
Dim r As Integer, c As Integer
Dim oTable As Word.Table = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range,DataGridView1.RowCount,DataGridView1.ColumnCo unt)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 0 To DataGridView1.RowCount - 2
For c = 0 To DataGridView1.ColumnCount - 1
oTable.Cell(r + 1, c + 1).Range.Text = DataGridView1(c, r).Value.ToString()
I did not really understand this part of the code:
Code:
For r = 0 To DataGridView1.RowCount - 2
For c = 0 To DataGridView1.ColumnCount - 1
oTable.Cell(r + 1, c + 1).Range.Text = DataGridView1(c, r).Value.ToString()
Why we need to minus 2 from the row and plus 1 at oTable.Cell?
Although I managed to copy the data over, the column's name was not copied over. Is it possible to copy the column name as well or does it always take the first data in the row as column name?
Thank you.
Regards,
shinichi90
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|