Excel로 이미지 내보내기

3203 단어
  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

좋은 웹페이지 즐겨찾기