隐藏

.net NPOI读取excel图片

发布:2023/3/25 0:19:30作者:管理员 来源:本站 浏览次数:826

      IWorkbook wk = null;
      List<string> base64Stringlist = new List<string>();
      using (FileStream fsReader = System.IO.File.OpenRead(strPath))//strPath文件路径
      {
             if (strPath.IndexOf(".xlsx") > 0)
                 wk = new XSSFWorkbook(fsReader);
             else if (strPath.IndexOf(".xls") > 0)
                 wk = new HSSFWorkbook(fsReader);
                 IList pictures = wk.GetAllPictures();
                 foreach (XSSFPictureData pic in pictures)
                  {
                       string base64String = Convert.ToBase64String(pic.Data);
                       base64Stringlist.Add(base64String);
                  }
       }