Get worksheet information from an Open XML package

Get worksheet information from an Open XML package

2016-01-15 06:38:39 Written by  Koohji
Rate this item
(0 votes)

class Program
    {
        static void Main(string[] args)
        {
            GetSheetInfo(@"..\..\Documents\Sheet4.xlsx");
        }
        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);
                    }
                }
            }
            Console.ReadLine();
        }
    }