[Advanced Excel] How can I know how many sheets has my Excel file?

[Advanced Excel] How can I know how many sheets has my Excel file?

  
Forge Component
(18)
Published on 2015-10-06 by Carlos Freitas
18 votes
Published on 2015-10-06 by Carlos Freitas
Hi,

I'm trying to use Worksheet_SelectedByIndex but how I know how many sheets I will have in my Excel file?
I will need that to iterate with all my Excel sheets to get the attributes from all sheets.

Do you have any idea how to do that. If I had that I will has a foreach running for the first sheet until to the last one (that I'm not able to know) and using ExcelToRecordList I will get the values from all sheets per sheet.

Thanks for your help

Kind regards,
Nuno Oliveira






Hi,

Without much knowledge of how this extension really works, one possible soulition might be to edit the extension and add a new action to return the number of worksheets. This will require you to write some C# code.
In C# I guess you can access the number of worksheets with something more or less like this:
            p = (ExcelPackage)ssWorkbook;
            wb = p.Workbook;
            number = wb.Worksheets.Count;

Regards,
Miguel