title: How to insert a table at the beginning of a docx document using NPOI
body: <p>I am trying to use NPOI to insert a new table at the beginning of an existing docx Word document.  Here is what the code looks like:</p>
  
  <pre><code>        FileStream fs = new FileStream("C:\\temp\\input.docx", FileMode.Open);
          XWPFDocument doc = new XWPFDocument(fs);
  
          XWPFTable table = new XWPFTable(new CT_Tbl(), doc, 2, 2);
          var par = table.GetRow(0).GetCell(0).AddParagraph();
          var run = new XWPFRun(new CT_R(), (IRunBody) par);
          run.AppendText("The quick brown fox was here.");
          par.AddRun(run);
  
          doc.InsertTable(0, table);
  
          FileStream output = new FileStream("C:\\temp\\output.docx", FileMode.Create);
  
          doc.Write(output);
  
          output.Close();
          fs.Close();
  </code></pre>
  
  <p>Unfortunately, this doesn't work.  The string and table are nowhere to be found in output.docx.  Does anyone have any idea why?</p>
  
  <p>I'm not too sure what a CT_R or CT_Tbl are, or how to make one, so perhaps that ias part of the issue.  With little to no documentation, hoping someone out there has experience with this popular NuGet library.</p>
  
  <p>Note: Other examples show how to add a table at the end of a doc, but not the beginning.</p>