title: How to hide a sheet in Excel using OpenXML C#?
body: <p>I have an Excel Template with various sheets to which I am dumping data retrieved from SQL Server using OpenXML, C#. 
  After I am done with dumping the data, I need to hide some of the sheets based on conditions. I couldn't find any piece of code to hide a particular sheet using C# OpenXML.</p>
  
  <p>I tried the following but the sheets did not get hidden.</p>
  
  <pre><code>byte[] byteArray = File.ReadAllBytes("D:\\rptTemplate.xlsx");
  using (MemoryStream mem = new MemoryStream())
  {
  mem.Write(byteArray, 0, (int)byteArray.Length);
  using (SpreadsheetDocument rptTemplate = SpreadsheetDocument.Open(mem, true))
  {
      foreach (OpenXmlElement oxe in (rptTemplate.WorkbookPart.Workbook.Sheets).ChildElements)
      {
       if(((DocumentFormat.OpenXml.Spreadsheet.Sheet)(oxe)).Name == "ABC")
          ((DocumentFormat.OpenXml.Spreadsheet.Sheet)(oxe)).State = SheetStateValues.Hidden;
      }
      rptTemplate.WorkbookPart.Workbook.Save();
  }
  }
  </code></pre>
  
  <p>Request help on this.</p>
  
  <p>Thanks.</p>