读取EXCEL中的图片

C#

 

private string exclePath = @"E:/111.xls";
private int StartRow = 2; //读的起始行
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Application excel = new Excel.Application();//引用Excel对象
Excel.Workbook workbook = excel.Workbooks.Add(exclePath);
excel.UserControl = true;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
excel.Visible = false;
for (int i = 0; i < workbook.Worksheets.Count; i++)//循环取所有的Sheet.
{
   Excel.Worksheet sheet = workbook.Worksheets.get_Item(i + 1) as Excel.Worksheet;//从1开始.
   for (int row = StartRow; row <= sheet.UsedRange.Rows.Count; row++)
   {
    //取单元格值;
    for (int col = 1; col <= sheet.UsedRange.Columns.Count; col++)
    {
     Excel.Range range =sheet.Cells[row, col] as Excel.Range;
     sb.Append("," + col.ToString() + ":" + range.Text);
    }
    sb.Append(System.Environment.NewLine);
    //取存图片;
    if(sheet.Shapes.Count > row - StartRow )
    {
     Excel.Shape s = sheet.Shapes.Item(row - StartRow + 1) as Excel.Shape;
     s.CopyPicture(Appearance.Button, Excel.XlCopyPictureFormat.xlBitmap); //COPY到内存。
     IDataObject iData = Clipboard.GetDataObject();
     if (iData.GetDataPresent(DataFormats.Bitmap))
     {
      pictureBox1.Image = (Bitmap)iData.GetData(DataFormats.Bitmap); //从内存取值;
      pictureBox1.Image.Save(string.Format(@"D:/{0}.jpg", row));   //保存。
     }
     else
     {
      pictureBox1.Image = null;
     }
    }
   }
    }
workbook.Close(false,null,null);
excel.Quit();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值