码迷,mamicode.com
首页 > Windows程序 > 详细

C# 导入图片到Excel单元格

时间:2017-03-24 10:34:11      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:宽度   convert   功能   ros   ice   rtp   add   str   距离   

导出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单元格

标签:宽度   convert   功能   ros   ice   rtp   add   str   距离   

原文地址:http://www.cnblogs.com/evansky/p/6609999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!