Lijo Joseph

Lijo Joseph

  • NA
  • 1
  • 4.9k

how to hide a row in excel using open xml?

Dec 17 2014 1:59 AM
I tried a lot for this. There are ways to read to a content from a hidden row but no ways to hide a row from an application. If anyone has a solution it will of great help if you share it.
Thanks in Advance 
The code below is the try i did. 
        const string fileName = @"C:\Users\ljoseph\Documents\Book1.xlsx";


            SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false);
            WorkbookPart wbPart = document.WorkbookPart;
            var sheets = wbPart.Workbook.Descendants<Sheet>();
            var sheet = sheets.First();


            var workSheet = ((WorksheetPart)wbPart.GetPartById(sheet.Id)).Worksheet;
            var sheetData = workSheet.Elements<SheetData>().First();
            var rows = sheetData.Elements<Row>().ToList();
            var row = rows.Where(r => r.RowIndex.Value == 2).First();
            row.Hidden = true;
            document.Close();
            Console.Read();

Answers (2)