将图片导出到Excel中

  public static void PictureToExcel(Data data,string fileTemplate, string feedbackFileName)
    {
        System.IO.FileStream file = new System.IO.FileStream(fileTemplate, FileMode.Open, FileAccess.Read);

        XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
        XSSFSheet ws1 = hssfworkbook.GetSheet("照片") as XSSFSheet;
        if (!string.IsNullOrEmpty(data.vcImagePath))
        {
            string[] paths = feedback.vcImagePath.Split(',');//多张图片逗号分隔
            for (int i = 0; i < paths.Length - 1; i++)
            {

                byte[] bytes = System.IO.File.ReadAllBytes(System.Web.HttpContext.Current.Request.MapPath(paths[i]));
                int pictureIdx = hssfworkbook.AddPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);

                XSSFDrawing patriarch = (XSSFDrawing)ws1.CreateDrawingPatriarch();
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 60, 14, i + 1, 1, i + 2, 2);
                XSSFPicture pict = (XSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
                //pict.Resize(0.9);

            }
        }
        }
        #endregion
       
        using (FileStream filess = File.OpenWrite(feedbackFileName))
        {
            hssfworkbook.Write(filess);
        }
    }

 

转载于:https://www.cnblogs.com/liyunworld/p/11250868.html

你可能感兴趣的:(将图片导出到Excel中)