title: C#, Write XLSX using OpenXmlWriter and Open XML SDK
body: <p>In C#, the following program compiles and runs, but it doesn't write anything in the excel output file.</p>
  
  <p>I got it working without the <code>OpenXmlWriter</code> but I started running out of memory so I have to switch to the <code>OpenXmlWriter</code> according to this <a href="http://blogs.msdn.com/b/brian_jones/archive/2010/06/22/writing-large-excel-files-with-the-open-xml-sdk.aspx" rel="nofollow">http://blogs.msdn.com/b/brian_jones/archive/2010/06/22/writing-large-excel-files-with-the-open-xml-sdk.aspx</a></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          File.Copy("book.xlsx", "output.xlsx", true);
          WriteValuesSAX("output.xlsx", 10, 10);
      }
  
      static void WriteValuesSAX(string filename, int numRows, int numCols)
      {
          using (SpreadsheetDocument myDoc = 
                 SpreadsheetDocument.Open(filename, true))
          {
              WorkbookPart workbookPart = myDoc.WorkbookPart;
              WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
  
              OpenXmlWriter writer = OpenXmlWriter.Create(worksheetPart);
  
              Row r = new Row();
              Cell c = new Cell();
              CellValue v = new CellValue("Test");
              c.AppendChild(v);
  
              writer.WriteStartElement(new SheetData());
              for (int row = 0; row &lt; numRows; row++)
              {
                  writer.WriteStartElement(r);
                  for (int col = 0; col &lt; numCols; col++)
                  {
                      writer.WriteElement(c);
                  }
                  writer.WriteEndElement();
              }
              writer.WriteEndElement();
  
              writer.Close();
          }
      }
  }
  </code></pre>
  
  <p>Why doesn't it write anything to output?</p>