datagridview image列导出为ex​​cel

时间:2017-04-16 20:53:31

标签: vb.net image datagridview

我有一个datagridview,其中包含多行文本,包括带图像的行。

Datagridview Image

当尝试使用以下代码将没有图像的文本导出时,我没有错误;

Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
    'Save to excel with headers
    Dim ExcelApp As Object, ExcelBook As Object
    Dim ExcelSheet As Object
    Dim i As Integer
    Dim j As Integer

    'create object of excel
    ExcelApp = CreateObject("Excel.Application")
    ExcelBook = ExcelApp.WorkBooks.Add
    ExcelSheet = ExcelBook.WorkSheets(1)

    With ExcelSheet
        For Each column As DataGridViewColumn In DataGridView1.Columns
            .cells(1, column.Index + 1) = column.HeaderText
        Next
        For i = 1 To Me.DataGridView1.RowCount
            .cells(i + 1, 1) = Me.DataGridView1.Rows(i - 1).Cells("NHS Number").Value
            For j = 1 To DataGridView1.Columns.Count - 1
                .cells(i + 1, j + 1) = DataGridView1.Rows(i - 1).Cells(j).Value
            Next
        Next
    End With

    ExcelApp.Visible = True
    '
    ExcelSheet = Nothing
    ExcelBook = Nothing
    ExcelApp = Nothing
End Sub

当我将图像包含到datagridview中以导出到excel时,我收到以下错误:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll

其他信息:未找到会员。 (HRESULT异常:0x80020003(DISP_E_MEMBERNOTFOUND))

有什么想法吗?

0 个答案:

没有答案