zoukankan      html  css  js  c++  java
  • [轉]c#从Excel中读取图片

    From : http://hi.baidu.com/o0o%CD%F5%D4%F3%C3%F1o0o/blog/item/e311bf252bdf4d3b8644f95f.html

    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();
    }
  • 相关阅读:
    asp.net HttpModule和HttpHandler
    Asp.Net生命周期和Http管道技术
    降低web服务器压力
    html里嵌入CSS的三种方式
    php实现简单视图模板(视图引擎)
    ASP.NET MVC路由配置
    igel udc2 config
    单IP、网络、别名管道限速的设置
    Apple SIP简介及在Clover中如何控制
    Hackintosh
  • 原文地址:https://www.cnblogs.com/Athrun/p/2227236.html
Copyright © 2011-2022 走看看