Search code examples
c#excelnpoi

How to enumerate excel worksheets in NPOI


How can I enumerate all the excel sheets name using NPOI? As a quick workaround, I'm using the following. But I feel super guilty for doing it...

        try
        {

            IWorkbook Iwb;
            Iwb = new XSSFWorkbook(filepath);

            int i = 0;
            while (i < 100)
            {
                MessageBox.Show(Iwb.GetSheetAt(i).SheetName);
                i++;
            }

        }
        catch (Exception ex)
        {//Do Nothing..
        }

Solution

  • There's a NumberOfSheets property that you can use.