比如说,第二行第二列里面存的是一张图片,现在要把它读取出来并且将该图片保存到D盘的某个位置,要怎么弄呢?找了好久也没找到相关方法,有知道的说声咯,谢谢

解决方案 »

  1.   

    我记得EXCEL中添加的图片必须是浮动在表格上,不能放入某个具体的单元格吧。
    //引用Excel命名空间
            using Excel;
            //......
            //下面从test.xls中的2,2格复制图片到剪贴板,然后从剪贴板读取图片并显示到pictureBox1中。
            private void btnGetImageFromExcel_Click(object sender, EventArgs e)
            {
                //初始化excel对象
                Excel.Application excel = new Excel.Application();
                //打开xls文件(注意:后面的参数都用Type.Missing填充,表示使用参数的默认值)
                excel.Workbooks.Open(@"D:\Documents and Settings\xrwang\桌面\test.xls", System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
                //选定到第2行第2列所在的单元格
                Range r = (Range)excel.Cells[2, 2];
                r.Select();
                //将单元格复制到剪贴板中
                r.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
                //退出excel
                excel.Quit();
                //判断剪贴板中是否存在图片,如果存在,则将图片显示到pictureBox1中
                if (Clipboard.ContainsImage())
                {
                    Image image=Clipboard.GetImage();
                    pictureBox1.Image = image;
                }
            }
      

  2.   

    npoi不支持图片的读取。
    想获得图片只有1楼的办法,而且效果不说了。
    无语。
      

  3.   

    呵呵,谢谢,这段代码复制不了图片try
    {
        /////////////////////////////////////////////////////
        //初始化excel对象
        Excel.Application excel = new Excel.Application();
        //打开xls文件(注意:后面的参数都用Type.Missing填充,表示使用参数的默认值)
        excel.Workbooks.Open(path, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
        //选定到第2行第2列所在的单元格
        Excel.Range r = (Excel.Range)excel.Cells[7, 8];
        Excel.Range r1 = (Excel.Range)excel.Cells[7, 7];
        Excel.Range r2 = (Excel.Range)excel.Cells[7, 9];
        //r.text="",r1=1,r2.text=2,均为图片表格前后的值
        p = r.Text.ToString() + r1.Text.ToString() + r2.Text.ToString();
        r.Select();
        //将单元格复制到剪贴板中
        r.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap);
        //,貌似总是复制不了图片!!!!!谁有更好的办法么?    //判断剪贴板中是否存在图片,如果存在,则将图片显示到pictureBox1中
        if (System.Windows.Forms.Clipboard.ContainsImage())
        {
            System.Drawing.Image image = (System.Drawing.Image)System.Windows.Forms.Clipboard.GetImage();
            pictureBox1.Image = image;
            pictureBox1.Image.Save(HttpContext.Current.Request.MapPath("~/ExcelFile/" + lbFileName.Text.Trim() + ".jpg"));
        }    excel.Quit();
        /////////////////////////////////////Read1(workbook);
        lblMes.Visible = true;
        string strText = FileUpload1.FileName;
        if (lblMes.Text == "111111")
        {
            lblMes.Text = strText + "  " + "数据导入失败,该数据在服务器已经存在";
        }
        else
        {
            lblMes.Text = strText + "  " + "数据导入成功";
        }
    }
    catch (Exception ex)
    {
        lblMes.Visible = true; ;
        string strText = FileUpload1.FileName;
        lblMes.Text = FileUpload1.FileName + " " + ex.Message + "请检查EXCEL文件中是否存在非标准格式内容";
        throw new Exception(ex.Message);
    }
    finally
    {
        //释放加载的文件
        //workbook = null;
        //File.Delete(path);
    }
      

  4.   

    哎这个方法貌似不能读取到图片啊,该怎么做呢?
    r.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap);
      

  5.   


    //是不是web项目不能使用这个方法呢,因为调试的时候发现data为null,而我的项目是web项目
    //web项目要怎么读取Excel里面的图片呢??大侠给点意见啊
    IDataObject data = Clipboard.GetDataObject();
    //这条if语出错,报未将对象引用设置到对象的实例,晕了,大侠们,帮忙啊
    if (data.GetDataPresent(DataFormats.Bitmap))
    {
     System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
     image.Save("test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    }我重新开了个贴,发现一个问题,路过的一起看看啊,谢谢了
    http://topic.csdn.net/u/20110708/14/3be3c6a4-d31e-4e91-8838-db7958839f01.html