Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi all,

I want to export all images from my image folder into excel. I want to place every image in the image folder into a new excel worksheet. For e.g. if there are 10 images in the folder, I want to have 10 excel worksheets on the same excel workbook with 1 image on each worksheet.

Question: How to Add Image From A Folder to Excel Worksheet Using EPplus with my current code?


This is my code:
C#
string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Image"));
                int count = 0;
                foreach (string img in filesindirectory)
                {
                    count++;
                 ExcelWorksheet ws = objExcelPackage.Workbook.Worksheets.Add("Worksheet - " + count); //create new worksheet
                    System.Web.UI.WebControls.Image TEST_IMAGE = new System.Web.UI.WebControls.Image();
                    TEST_IMAGE.ImageUrl = "Image/" + Path.GetFileName(img);
                    TEST_IMAGE.ImageUrl = this.GetAbsoluteUrl(TEST_IMAGE.ImageUrl);
                    
                   //I want to insert image here

var filepath= new FileInfo(@"C:\Users\user\Desktop\folder\" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx");
                        objExcelPackage.SaveAs(filepath);

Please help me on this, I am stuck, thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900