0
Answer

how to hide a row in excel using open xml?

Ask a question
Lijo Joseph

Lijo Joseph

9y
1.6k
1
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();

Next Recommended Forum