zoukankan      html  css  js  c++  java
  • POI在导出的EXCEL中嵌入图片

     string filename = ComMethod.ObjToString(Table1.Rows[index]["files"]);    

      if (!string.IsNullOrEmpty(filename))                  

       {                       

      string path = Server.MapPath(ConfigurationManager.AppSettings["ArtworkFile"]);                     

        string readpath = path + filename;                       

      FileInfo file = new System.IO.FileInfo(readpath);                        

    if (!file.Exists)                        

    {                            

    ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + readpath + ",该文档不存在!');</script>");                    

         }

                       

         byte[] bytes = System.IO.File.ReadAllBytes(readpath);                         //byte[] bytes = System.IO.File.ReadAllBytes("E:\\ttt\\Chrysanthemum.jpg");                         int pictureIdx = hssfworkbook.AddPicture(bytes, PictureType.JPEG);

                            // Create the drawing patriarch.  This is the top level container for all shapes.                         HSSFPatriarch patriarch = (HSSFPatriarch)excelSheet.CreateDrawingPatriarch();

                            //add a picture,hssfclientanchor包含8个参数,其中,后面四个参数分别指嵌入图片的位置                         HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 0, (short)(2 + tablesize.Rows.Count), 5, 11, (short)(startrow + deletecount1));

                            patriarch.CreatePicture(anchor, pictureIdx);                     }

  • 相关阅读:
    使用HTTP协下载文件
    DNS协议 实践
    操作系统学习笔记 线程
    操作系统学习笔记 进程
    操作系统学习笔记 操作系统概述
    操作系统学习笔记 栈
    操作系统学习笔记 概述
    C语言中的fread和fwrite
    【原】python-jenkins信息
    【转】通过python调用jenkins 常用api操作
  • 原文地址:https://www.cnblogs.com/zhuxiaohui/p/2760192.html
Copyright © 2011-2022 走看看