首页 > 代码库 > C# 导入图片到Excel单元格
C# 导入图片到Excel单元格
导出Excel功能时需要将数据中含有图片也导出到excel单元格中
public void InsertPicture(string RangeName, string PicturePath, Microsoft.Office.Interop.Excel.Worksheet worksheet) { Microsoft.Office.Interop.Excel.Range m_objRange = worksheet.get_Range(RangeName, Type.Missing); m_objRange.Select(); float PicLeft, PicTop, PicWidth, PicHeight; //距离左边距离,顶部距离,图片宽度、高度 PicTop = Convert.ToSingle(m_objRange.Top); PicWidth = Convert.ToSingle(m_objRange.MergeArea.Width); PicHeight = Convert.ToSingle(m_objRange.Height)-10; PicWidth = Convert.ToSingle(m_objRange.Width)-10; PicLeft = Convert.ToSingle(m_objRange.Left);//+ (Convert.ToSingle(rng.MergeArea.Width) - PicWidth) / 2; try { //worksheet.Shapes.AddPicture(PicturePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, PictuteWidth, PictureHeight); worksheet.Shapes.AddPicture(PicturePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, 90, 70); } catch { } }
C# 导入图片到Excel单元格
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。