微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Vb.net 无法将带有图像的数据从 access 传输到 excel

如何解决Vb.net 无法将带有图像的数据从 access 传输到 excel

嗨,有没有办法将带有图像的访问数据库传输到excel?由于我的图像使用 ole 对象。

    Private Sub Button2_Click(sender As Object,e As EventArgs) Handles Button2.Click
    If DataGridView1.RowCount = nothing Then
        MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf & "Please retrieve data in datagridview","",MessageBoxButtons.OK,MessageBoxIcon.Error)
        Exit Sub
    End If
    Dim rowsTotal,colsTotal As Short
    Dim I,j,iC As Short
    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    Dim xlApp As New excel.Application

    Try
        Dim excelBook As excel.Workbook = xlApp.Workbooks.Add
        Dim excelWorksheet As excel.Worksheet = CType(excelBook.Worksheets(1),excel.Worksheet)
        xlApp.Visible = True

        rowsTotal = DataGridView1.RowCount - 1
        colsTotal = DataGridView1.Columns.Count - 1
        With excelWorksheet
            .Cells.Select()
            .Cells.Delete()
            For iC = 0 To colsTotal
                .Cells(1,iC + 1).Value = DataGridView1.Columns(iC).HeaderText
            Next
            For I = 0 To rowsTotal - 1
                For j = 0 To colsTotal
                    .Cells(I + 2,j + 1).value = DataGridView1.Rows(I).Cells(j).Value
                    .Shapes.AddPicture("C:\pic.jpg",MsoTristate.msofalse,msotristate.msoCTrue,50,300,45) <-I just add this to transfer the image
                Next j
            Next I
            .Rows("1:1").Font.FontStyle = "Bold"
            .Rows("1:1").Font.Size = 12
            .Cells.Columns.AutoFit()
            .Cells.Select()
            .Cells.EntireColumn.AutoFit()
            .Cells(1,1).Select()

        End With
    Catch ex As Exception
        MessageBox.Show(ex.Message,"Error",MessageBoxIcon.Error)
    Finally
        'RELEASE ALLOACTED RESOURCES
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
        xlApp = nothing
    End Try
End Sub

如果数据没有任何图片,那么它可以被传输,但图像它只是不起作用......我一直在关注一些演练,我只是添加了该代码以允许图片传输。

我使用的导入:

Imports system.data.oledb
Imports microsoft.office.core
imports excel = microsoft.office.interop.excel

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。