Remove Word Table in C#, VB.NET

Word tables can be removed if the data information isn’t related to document contents or unnecessary any more. In this example, the solution to remove the specified Word table(first one in example) in C# and VB.NET with Spire.Doc for .NET. And the following screenshot presents original Word document with the first table.

Remove Word Table

Spire.Doc for .NET provides a RemoveAt(int index) method of TableCollection class to remove specified table in Word document. Because tables are stored in Section, so it needs to get specified Section of Document at first. Then invoke TableCollection.RemoveAt method to remove specified tables. Download and Install Spire.Doc for .NET and follow the code.

[C#]
using Spire.Doc;

namespace RemoveTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document(@"E:\Work\Documents\.NET Framework.docx");

            //Remove the First Table            
            doc.Sections[0].Tables.RemoveAt(0);
            
            //Save Document
            doc.SaveToFile("RemoveTable.docx", FileFormat.Docx);
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace RemoveTable
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim doc As New Document("E:\Work\Documents\.NET Framework.docx")

            'Remove the First Table            
            doc.Sections(0).Tables.RemoveAt(0)

            'Save Document
            doc.SaveToFile("RemoveTable.docx", FileFormat.Docx)
        End Sub
    End Class
End Namespace

After debugging and opening the saved document, you can find that the first table of document has been removed.

Remove Word Table

Spire.Doc, a professional Word component, enables developers/programmers to operate Word document, for example, generating, opening, saving and modifying on .NET, WPF and Silverlight applications