Try this
Dim row As Integer = 1
Dim col As Integer = 1
For Each line As DataGridViewRow In grdToExport.Rows
For Each cell As DataGridViewTextBoxCell In line.Cells
sheet.Cells(row, col) = cell.Value
col = col + 1
Next
row += 1
col = 1
Next
Reverend Jim
Posting Shark
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
I'll tell you what I think is the problem, then I'll apologize for not mentioning it explicitly, then I'll rant just a little.
Try adding the following two lines at the top
Imports Microsoft.Office.Interop
Imports System.Windows.Forms
I apologize for not mentioning that explicitly before (but I repeat myself). And I asumed you already knew to add a Reference (COM) of the form Microsoft Excel 11.0 Object Library (depending on which version of Office you have)
One thing that annoys me (even more so when I am caught doing it), is when people post a partial solution. And by that I mean a solution that would be obvious to someone who already knows what to do but not enough for the person who is asking the question. A case in point is assuming that you knew to add the correct "Imports" info. Another case (more insidious) is when people assume you know what references to add to the project to make something work. When they actually DO say to add a reference, do they mean "reference" or "service reference". If reference, do they mean from the ".NET", "COM", "Browse", etc tab? When they say "add a SQL reference", which of the 20 odd references do they mean and do they mention the actual reference name (full name) as it appears in the reference list?
There are so many details that the experts know (without having to actively think about them) that trip up the rest of us. And knowing 99.9 percent of what to do, but missing that 0.1 percent that is impossible to deduce just leads to endless frustration.
But that's just my opinion. I could be wrong ;-)
Reverend Jim
Posting Shark
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
If this is not a web app then try changing the GridView control to a DataGridView control. I have never done web development so I have no experience in that area.
Reverend Jim
Posting Shark
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
Any time. Please remember to mark this thread as solved.
Reverend Jim
Posting Shark
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159