如何从数据网格视图粘贴excel单元格中的图像

问题描述:

HI

我在vb.net中使用数据网格视图。我在数据网格视图中有以下列

I am using data grid view in vb.net. I have following columns in data grid view

学生ID

名称

学生参与

当我复制网格数据并将其粘贴到Excel工作表时,它会粘贴除图像数据之外的所有数据。

when I copy the grid data and paste it into excel worksheet it paste all data except image data.

指导我如何克服这个问题,手动复制和粘贴或以编程方式。

please guide me how to overcome this problem either manually copy and paste or programmatically.

谢谢

RoniDxb

您好,

首先,如果使用.xlsx然后我强烈推荐使用
SpreadSheetLight
(免费库),它可以通过NuGet包含在您的项目中,来自
此页面。请注意,网站上也有一个很棒的帮助文件。

First off, if working with .xlsx then I highly recommend using SpreadSheetLight (free library) which can be included in your project via NuGet, from this page. Note there is a great help file on the site too.

基本要求是知道图像源,以便可以从磁盘读取,或者您需要将图像作为字节数组获取来自DataGridView并使用其中一个SLPicture重载字节

Basic requirement is to know the image source so it can be read from disk or you will need to get the image as a byte array from the DataGridView and use one of the SLPicture overloads for bytes

Imports SpreadsheetLight
Imports SpreadsheetLight.Drawing
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using sl As New SLDocument("SomeFile.xlsx", "SomeSheet")
            Dim pic As New SLPicture("C:\SomePicture.bmp")
            pic.SetPosition(2, 1)
            sl.InsertPicture(pic)
            sl.Save()
        End Using
    End Sub
End Class


如果这不是你的口味,那么你需要使用Excel自动化,这需要比SpreadSheetLight更多的代码,而SpreadSheetLight则不需要需要安装Excel led。

If that is not your taste then you would need to use Excel automation which requires more code than SpreadSheetLight does and SpreadSheetLight does not need to have Excel installed.