zoukankan      html  css  js  c++  java
  • 利用NPOI给excel文件中添加图片

    利用NPOI给excel中添加图片

    核心代码,可自行封装

     var imgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "seal.png");
     var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tttt.xls");
     var newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "aaaa.xls");
     var buffer = File.OpenRead(filePath);
     var bytes = File.ReadAllBytes(imgPath);
     var workbook = new HSSFWorkbook(buffer);
     var sheet = workbook.GetSheetAt(0);
     var drawing = sheet.CreateDrawingPatriarch();
     var pic = workbook.AddPicture(bytes, PictureType.PNG);
     var anchor = new HSSFClientAnchor();
     anchor.SetAnchor(
        short.Parse(Col1.Text),
         int.Parse(Row1.Text),
        int.Parse(X1.Text),
         int.Parse(Y1.Text),
         short.Parse(Col2.Text),
         int.Parse(Row2.Text),
         int.Parse(X2.Text),
         int.Parse(Y2.Text));
     anchor.AnchorType = AnchorType.MoveAndResize;
     drawing.CreatePicture(anchor, pic);
     using (var fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
     {
         workbook.Write(fs);
     }
    

    参数说明:

    image.png

  • 相关阅读:
    flask 指定前端文件路径以及静态文件路径
    pycharm git修改密码
    Web应用搭建
    python学习
    python解析jSON文件
    通过DLNA将电脑视频投射到电视屏幕
    U盘自动复制文件
    kali PIN码破解
    mdk3洪水攻击教程
    sqlmap(网站数据库注入)
  • 原文地址:https://www.cnblogs.com/dongteng/p/13955135.html
Copyright © 2011-2022 走看看