title: how to display the content of table in word document eliminating the empty table using c#
body: <p>I have 5 tables in which only 3 tables have content and 2 tables are empty.</p>
  
  <p>I want to write a c# code to extract only the tables which have content. The tables are in a Word document.</p>
  
  <p>My code:</p>
  
  <pre><code>string path = @"C:\Gokul\Word File\Change Control Deployment Instructions.docx";
  
  
  Word.Application wordApp = new Word.Application();
  object file = path;
  object nullobj = System.Reflection.Missing.Value;
  object routedocument=false;
  Word.Document doc = wordApp.Documents.Open(
  ref file, ref nullobj, ref nullobj, ref nullobj,
                                        ref nullobj, ref nullobj, ref nullobj,
                                        ref nullobj, ref nullobj, ref nullobj,
                                        ref nullobj, ref nullobj, ref nullobj,
                                        ref nullobj, ref nullobj, ref nullobj);
  
  Word.Document wordDocument = doc as Word.Document;
  int tablecount = wordDocument.Tables.Count;
  wordDocument.Activate();
  for (int i = 1; i &lt;= tablecount; i++)
  {
      string rowtext;
  
  
      Word.Table wTable = wordDocument.Tables[i];
      rowtext = wTable.Rows.ToString();
  
      try
      {
          rowtext=rowtext.Replace('\r',' ').Replace('\a',' ').Trim();
      }
      catch{}
      if (string.IsNullOrEmpty(rowtext))
      {
          wTable.Rows[i].Delete();
          i--;
      }
      Word.Cells pCells = wTable.Range.Cells;
  
     Word.Row gok = wTable.Rows[1];
      Word.Cell pve=   wTable.Cell(1, 1);
      string h = pve.Range.Text;
      h = h.Replace("\r\a", "");
  
      Console.WriteLine(h);
  
      // if (h == "Stored Procedure")
      {
           for (int j = 2; j &lt;= wTable.Rows.Count; j++)
           {
               Word.Cell pCell = wTable.Cell(j,2);
               string k = pCell.Range.Text;
               Console.WriteLine(k);
           }
      }
  
   }
  
  Console.ReadLine();
  
  wordDocument.Close(ref file, ref nullobj,ref routedocument);
  </code></pre>