title: Adding Table to Existed Word Document using DocX
body: <p>I need to add table with some data to an existed Word template and I'm using novacode-docx Lib. 
  However, there is an issue that I can't locate. For some templates, everything works fine but for others I'm getting an error. So here is my code </p>
  
  <pre><code>//copying template file
  File.Copy(Info.reportTemplatePath+reportTemplateName+".docx",(path + fileName));
  var doc = DocX.Load(path + fileName);
  Table tb = doc.AddTable(3,3);
  //Table tb = doc.InsertTable(0, 3,3); 
  Font font = new Font(new FontFamily("Times New Roman"), 12f,FontStyle.Bold);
  tb.Alignment = Alignment.both;
  tb.Paragraphs[0].Font(new FontFamily("Times New Roman"));
  
  tb.Design = TableDesign.TableNormal;
  tb.SetBorder(TableBorderType.Bottom, new Border(BorderStyle.Tcbs_none, 0,1,Color.Transparent));
  tb.Rows[0].Cells[0].Paragraphs[0].Append("Patient Name: "+mirrorText(patientName) ).Alignment=Alignment.left; 
  tb.Rows[0].Cells[1].Paragraphs[0].Append("DOB: " +DOB  );
  tb.Rows[0].Cells[2].Paragraphs[0].Append("Visit Date: "+visitDate  ).Alignment = Alignment.right;
  tb.Rows[1].Cells[0].Paragraphs[0].Append("Patient ID: " + patientID).Alignment=Alignment.left;
  tb.Rows[1].Cells[2].Paragraphs[0].Append(" ");
  tb.Rows[2].Cells[2].Paragraphs[0].Append("المحترم "+mirrorText(referredDoctor) + " الدكتور " + " :المرسل " + "الطبيب").Alignment = Alignment.right;
  tb.Rows[0].Cells[0].Width = 330d;
  tb.Rows[0].Cells[1].Width = 190d;
  tb.Rows[0].Cells[2].Width = 220d;
  tb.Rows[0].Cells[2].Paragraphs[0].FontSize(12);
  tb.Rows[0].Cells[1].Paragraphs[0].FontSize(12);
  tb.Rows[0].Cells[0].Paragraphs[0].FontSize(12);
  tb.Rows[1].Cells[0].Paragraphs[0].FontSize(12);
  tb.Rows[2].Cells[2].Paragraphs[0].FontSize(14);
  tb.Rows[0].Cells[2].Paragraphs[0].Bold();
  tb.Rows[0].Cells[1].Paragraphs[0].Bold();
  tb.Rows[0].Cells[0].Paragraphs[0].Bold();
  tb.Rows[1].Cells[0].Paragraphs[0].Bold();
  tb.Rows[2].Cells[2].Paragraphs[0].Bold();
  tb.Rows[0].Cells[2].Paragraphs[0].Font(new FontFamily("Times New Roman"));
  tb.Rows[0].Cells[1].Paragraphs[0].Font(new FontFamily("Times New Roman"));
  tb.Rows[0].Cells[0].Paragraphs[0].Font(new FontFamily("Times New Roman"));
  tb.Rows[1].Cells[0].Paragraphs[0].Font(new FontFamily("Times New Roman"));
  tb.Rows[2].Cells[2].Paragraphs[0].Font(new FontFamily("Times New Roman"));
  tb.Rows[2].MergeCells(0, 2);
  tb.Rows[2].Cells[0].RemoveParagraphAt(0);
  tb.Rows[2].Cells[0].RemoveParagraphAt(0);
  
  doc.InsertTable(0,tb); // I am getting the error here which is {"Object reference not set to an instance of an object."}
  //   doc.InsertParagraph("المحترم " + mirrorText(referredDoctor) + " الدكتور " + " :المرسل " + "الطبيب", false, patientFormat).Alignment = Alignment.right;
  doc.InsertParagraph(string.Empty, false);
  doc.AddFooters();
  doc.MarginBottom = 0.1f;
  Footer footer = doc.Footers.odd;
  Bitmap tempFoImg = Info.generateFooterImage();
  //  System.Drawing.Image tempImg=(System.Drawing.Image)tempFoImg;
  
  MemoryStream ms2 = new MemoryStream();
  tempFoImg.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
  ms2.Seek(0, SeekOrigin.Begin);
  Novacode.Image img2 = doc.AddImage(ms2);
  Picture footerImage = img2.CreatePicture();
  Paragraph p4 = footer.InsertParagraph("", false).InsertPicture(footerImage, 0);
  p4.Alignment = Novacode.Alignment.center;
  doc.Save();
  Process.Start(path + fileName);
  </code></pre>
  
  <p>The error is located here :   <code>doc.InsertTable(0,tb); //  {"Object reference not set to an instance of an object."}</code>
  I am using  0 to append the table at the top of the document, and when I remove the location, it works fine some times 
  I am willing to use different lib. if it solves the problem, and thank you in advance</p>