class Program
{
static void Main(string[] args)
{
const string DEMOFILE = @"..\..\Documents\Sheets12.xlsx";
var results = GetAllWorksheets(DEMOFILE);
foreach (Sheet item in results)
{
Console.WriteLine(item.Name);
}
Console.ReadLine();
}
// Retrieve a List of all the sheets in a workbook.
// The Sheets class contains a collection of
// OpenXmlElement objects, each representing one of
// the sheets.
public static Sheets GetAllWorksheets(string fileName)
{
Sheets theSheets = null;
using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false))
{
WorkbookPart wbPart = document.WorkbookPart;
theSheets = wbPart.Workbook.Sheets;
}
return theSheets;
}
}