title: SheetViews is null trying to freeze rows openXML
body: <p>trying to reference this link:</p>
  
  <p><a href="https://social.msdn.microsoft.com/Forums/office/en-US/e1c08add-b610-44c9-b60e-fa8ef6c24978/openxmlexcelc?forum=oxmlsdk" rel="nofollow noreferrer">https://social.msdn.microsoft.com/Forums/office/en-US/e1c08add-b610-44c9-b60e-fa8ef6c24978/openxmlexcelc?forum=oxmlsdk</a></p>
  
  <p>I am getting a sheetview null pointer exception on this line:</p>
  
  <p>SheetView sw = wsp.Worksheet.SheetViews.FirstOrDefault() asSheetView;</p>
  
  <p>I am not using any sheetviews when creating my spreadsheet, and I am using memorystream to pass back to use.</p>
  
  <p>Using this code:</p>
  
  <p>How would I freeze the top two rows? Thanks!</p>
  
  <pre><code>MemoryStream ms = new MemoryStream();
          SpreadsheetDocument xl = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook);
  
          WorkbookPart wbp = xl.AddWorkbookPart();
          WorksheetPart wsp = wbp.AddNewPart&lt;WorksheetPart&gt;();
          Workbook wb = new Workbook();
          FileVersion fv = new FileVersion();
          fv.ApplicationName = "Microsoft Office Excel";
          Worksheet ws = new Worksheet();
  
          SheetData sd = new SheetData();
  
          WorkbookStylesPart stylesPart = xl.WorkbookPart.AddNewPart&lt;WorkbookStylesPart&gt;();
          stylesPart.Stylesheet = GenerateStyleSheet();
          stylesPart.Stylesheet.Save();
  
  
  
  
          //create header
          uint colHeaderIndex = 1;
          Row r1 = new Row() { RowIndex = colHeaderIndex };
          foreach (System.ComponentModel.PropertyDescriptor descriptor in System.ComponentModel.TypeDescriptor.GetProperties(list[0]))
          {
              Cell headerCell = new Cell();
              headerCell.DataType = CellValues.String;
              headerCell.CellValue = new CellValue(descriptor.DisplayName);
              r1.Append(headerCell);
          }
          //append header row to sheet
          sd.Append(r1);
  
  
          //now fill the rest of the rows with data
          uint rowIndex = 1; //Start at 1, since we reserved index 1 for the heading. The indexer will increase its value by 1 before it is used.  
          for (int i = 0; i &lt; list.Count; i++)
          {
              uint colIndex = 1;
              Row row = new Row() { RowIndex = ++rowIndex };
              foreach (System.ComponentModel.PropertyDescriptor descriptor in System.ComponentModel.TypeDescriptor.GetProperties(list[i]))
              {
                  Cell cell = new Cell();
                  cell.CellReference = rowIndex + " x " + colIndex;
                  cell.DataType = CellValues.String;
                  cell.StyleIndex = 1;
                  var val = descriptor.GetValue(list[i]);
                  cell.CellValue = new CellValue(val != null ? val.ToString() : "");
                  row.Append(cell);
              }
  
              //append data row to sheet
              sd.Append(row);
          }
  
          ws.Append(sd);
          wsp.Worksheet = ws;
          wsp.Worksheet.Save();
          Sheets sheets = new Sheets();
          Sheet sheet = new Sheet();
          sheet.Name = "first sheet";
          sheet.SheetId = 1; //we will only have one sheet for now, unless we are maxing out on sheets then we can create new ones
          sheet.Id = wbp.GetIdOfPart(wsp);
          sheets.Append(sheet);
          wb.Append(fv);
          wb.Append(sheets);
          freezeHeader(wbp, wsp);
          xl.WorkbookPart.Workbook = wb;
          xl.WorkbookPart.Workbook.Save();
  
          xl.Close();
  
          Response.Clear();
          byte[] dt = ms.ToArray();
  
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", fileName));
          Response.BinaryWrite(dt);
          Response.End();
  </code></pre>