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

I have exported image from my image folder into Excel on 1 Excel worksheet, does anyone know how can I name the excel worksheet as the Image folder name?

Currently the name of the worksheet is "Worksheet0", I want worksheet name to be the name of Image folder "ImageFolder".

This is my code:
C#
public void ExportToExcel()
        {
            //for export
            ExcelPackage objExcelPackage = new ExcelPackage();   //create new workbook

            string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Image"));
            int count = 0;
 
            ExcelWorksheet ws = objExcelPackage.Workbook.Worksheets.Add("Worksheet" + count); //create new worksheet

                        foreach (string img in filesindirectory)
                        {
                        count++;
                        System.Web.UI.WebControls.Image TEST_IMAGE = new System.Web.UI.WebControls.Image();
                        System.Drawing.Image myImage = System.Drawing.Image.FromFile(img);
                        var pic = ws.Drawings.AddPicture(count.ToString(), myImage);
                        // Row, RowoffsetPixel, Column, ColumnOffSetPixel
                        pic.SetPosition(1, 0, 2, 0);
                            }
                    }                            
            var filepath = new FileInfo(@"C:\Users\user\Desktop\Test\" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx");
            objExcelPackage.SaveAs(filepath);
        }

Appreciate if someone can help me on this, thanks.
Posted
Comments
Joshi, Rushikesh 23-Oct-15 12:09pm    
This is EPPlus specific questions, I would advice you to ask on their forum. There you will get more visibility

http://epplus.codeplex.com/discussions

Or refer http://www.codeproject.com/Articles/680421/Create-Read-Edit-Advance-Excel-Report-in

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