Get worksheet information - asposemarketplace/Aspose_for_OpenXML GitHub Wiki
OpenXML Excel:
using DocumentFormat.OpenXml.Packaging;
using S = DocumentFormat.OpenXml.Spreadsheet.Sheets;
using E = DocumentFormat.OpenXml.OpenXmlElement;
using A = DocumentFormat.OpenXml.OpenXmlAttribute;
class Program
{
static void Main(string[] args)
{
GetSheetInfo("Get worksheet information.xlsx");
Console.ReadKey();
}
public static void GetSheetInfo(string fileName)
{
// Open file as read-only.
using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(fileName, false))
{
S sheets = mySpreadsheet.WorkbookPart.Workbook.Sheets;
// For each sheet, display the sheet information.
foreach (E sheet in sheets)
{
foreach (A attr in sheet.GetAttributes())
{
Console.WriteLine("{0}: {1}", attr.LocalName, attr.Value);
}
}
}
}
}
Aspose.Cells:
class Program
{
static void Main(string[] args)
{
GetSheetInfo("Get worksheet information.xlsx");
Console.ReadKey();
}
private static void GetSheetInfo(string fileName)
{
//Instantiating a Workbook object
Workbook workbook = new Workbook(fileName);
//Loop through all Sheets in the workbook
foreach (Worksheet Sheet in workbook.Worksheets)
{
//Get Name and Index of Sheet
Console.WriteLine("Sheet Name: {0}", Sheet.Name);
Console.WriteLine("Sheet Index: {0}", Sheet.Index);
//Loop through all custom properties
foreach (CustomProperty Property in Sheet.CustomProperties)
{
Console.WriteLine("{0}: {1}", Property.Name, Property.Value);
}
}
}
}
Download