winform 中使用NPOI往excel的某个单元格插入图片时,使用Resize(0.9)后图片总在单元格的左上角。怎么调整使该图片居中显示???在线求,谢谢!
实现代码                           XSSFDrawing patriarch = (XSSFDrawing)sheet1.CreateDrawingPatriarch();
                           
                            // 插图片的位置  HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2) 后面再作解释
                            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, len, rowline, len + 1, rowline + 1);
                            //把图片插到相应的位置
                            XSSFPicture pict = (XSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
                 
                            pict.Resize(0.9);效果图

解决方案 »

  1.   

    XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, cols, rows, cols + 1, rows + 1);
                    anchor.Dx1 = 100000;
                    anchor.Dy1 = 20000;
                    anchor.Dx2 = -100000;
                    anchor.Dy2 = -20000;Dx1 Dy1 Dx2 Dy2 就是四边距离,以万为单位
      

  2.   

    不知道NPOI是如何操作的,我用Spire.XLS可以这样操作:
    using Spire.Xls;
    using System.Drawing;namespace AlignImageWithinACell
    {
        class Program
        {
            static void Main(string[] args)
            {
                //创建Workbook对象
                Workbook wb = new Workbook();            //获取第一个工作表
                Worksheet sheet = wb.Worksheets[0];            //获取图片地址
                string picPath = @"C:\Users\Administrator\Desktop\QR.jpg";            //将图添加到工作表的第一个单元格
                ExcelPicture picture = sheet.Pictures.Add(1, 1, picPath);            //设置单元格的高宽,使单元格能够容纳图片
                sheet.Columns[0].ColumnWidth = 25;
                sheet.Rows[0].RowHeight = 120;            //调整图片在单元格中做偏移量和上偏移量
                picture.LeftColumnOffset = 150;
                picture.TopRowOffset = 30;            //保存文档
                wb.SaveToFile("AlignPicture.xlsx", ExcelVersion.Version2013);
                System.Diagnostics.Process.Start("AlignPicture.xlsx");
            }
        }
    }效果:
      

  3.   

    看这个帖子http://www.cnblogs.com/atao/archive/2009/09/28/1576044.html
      

  4.   

    https://blog.csdn.net/echoshinian100/article/details/38540321还有这个