Я использую этот код
Dim ht2 As Table
For i As Integer = 0 To _RowCount2 - 2
For _col As Integer = 0 To _ColCount2 - 1
Dim colType As Type = Form2.DataGridView2.Columns(_col).GetType
If colType.Name = "DataGridViewImageColumn" Then
Dim _image As Image = DirectCast(Form2.DataGridView2.Rows(i).Cells(_col).FormattedValue, Image)
Clipboard.SetImage(_image)
ht2.Cell(i + 1, _col + 1).Range.Paste()
Else
ht2.Cell(i + 1, _col + 1).Range.Text = Form2.DataGridView2.Rows(i).Cells(_col).Value.ToString()
End If
Next
Next
Предполагается экспортировать Datagridview в слово, но в нем не отображаются заголовки столбцов. в основном я получаю ошибку исключения в этой строке
Dim _image As Image = DirectCast(Form2.DataGridView2.Rows(i).Cells(_col).FormattedValue, Image)