skip to Main Content

Hi I am not sure how I can achieve it. How I can get the sheet names of an excel file using Epplus? I tried the below code but its not giving the output.

 FileInfo fileInfo = new FileInfo(currentDir + @"/seo easier/" + "Backlinks_With_Logins.xlsx");
            using (var package = new ExcelPackage(fileInfo))
            {
              package.Workbook.Worksheets.Select(x => x.Name);

            }

2

Answers


  1. Chosen as BEST ANSWER

    I achieved it with the following code.

    FileInfo fileInfo = new FileInfo(currentDir + @"/seo easier/" + "Backlinks_With_Logins.xlsx");
                var excel = new ExcelPackage(fileInfo);
    
                foreach (var worksheet in excel.Workbook.Worksheets)
                {
                    this.comboBoxExcelSheetNames.Items.Add(worksheet.Name);
                }
    

  2. Your code seems to work but it doesn’t seem like you’ve put any code to output the names of the worksheets. Try adding a return statement like this:

    return package.Workbook.Worksheets.Select(x => x.Name);
    

    Or assigning it to a variable and then outputting that:

    var worksheets = package.Workbook.Worksheets.Select(x => x.Name);
    foreach (var sheet in worksheets) Console.WriteLine(sheet);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search