0

我想在 datagridview 中加载图像,但到目前为止我只得到文本。

代码

private void button1_Click(object sender, EventArgs e)
        {
            String name = "LOTUS";
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\xy\\Downloads\\SCA.xls;Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';");

            OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
            con.Open();

            OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
            DataTable data = new DataTable();
            sda.Fill(data);
            dataGridView1.DataSource = data;
        }
4

1 回答 1

0

从此博客中,有一个带有剪贴板的解决方案。

像这样的东西:

string shapeName = "";

for (int i = 0; i < sheet.Shapes.Count;i++ )
{
   Microsoft.Office.Interop.Excel.Shape shape=sheet.Shapes.Item(i);
   if (shape.Type == MsoShapeType.msoPicture)
   {
      shapeName = shape.Name;
   }
}

Worksheet sheet = GetFirstSheet();
if (sheet != null)
{                    
    Picture pict = sheet.Pictures(shapeName ) as Picture;
    pict.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);                 
}

if (Clipboard.ContainsImage())
{
   Image img=Clipboard.GetImage();
   pbPicture.Image = img;
}
于 2013-06-28T21:39:32.220 回答