现在工程中已经实现打开EXCEL对象,直接利用workSheet.Cells[x,x]输入字符型数据,但如今要求在具体单元格中插入图片,请教各位高手如何实现???

解决方案 »

  1.   

    /// <summary>
    /// 插入图片
    /// </summary>
    /// <param name="fileName">图片文件名(带路径)</param>
    /// <param name="left">left</param>
    /// <param name="top">top</param>
    /// <param name="width">宽</param>
    /// <param name="height">高</param>
    public void InsertPicture(string fileName,
    float left,float top,float width,float height)
    {
    try
    {
    objSheet.Shapes.AddPicture(fileName,Microsoft.Office.Core.MsoTriState.msoTrue,
    Microsoft.Office.Core.MsoTriState.msoTrue,left,top,width,height);
    }
    catch
    {
    throw new Exception("");
    }
    }
      

  2.   

    用宏录制一下你的手工操作,然后到VBA里面看一下,应该可以找到相关的代码的
      

  3.   

    按照Eddie005(♂) 暴赱 『零零伍』(︶︵︶) 的做法能够插入图片,但如何定位具体单元格的方法没有找到???
      

  4.   

    前2天刚学会的,不过是vb的,看能翻译成C#不
    With ws.Cells(iRow, img_col)   'ws是个worksheet对象
    Set pic = .Parent.Pictures.Insert(pic_file_name) '搞不清除pic到底是什么对象,声明为object就行
    aspect = pic.Height / pic.Width '高宽比
    pic.Top = .Top + 2
    pic.Left = .Left 
    pic.Width = .Width 
    pic.Height = (pic.Width * aspect)
    .RowHeight = pic.Height + 4
    End With