Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Remove table row
The example shows you how to remove table's row.
C# example
using System; using System.Collections.Generic; using Independentsoft.Office.Word; using Independentsoft.Office.Word.Tables; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument("c:\\test\\input.docx"); IList
tables = doc.GetTables(); Table table1 = tables[0]; //first table int rowCount = 0; for (int i = 0; i < table1.Content.Count; i++) { if (table1.Content[i] is Row) { Row currentRow = (Row)table1.Content[i]; rowCount++; if (rowCount == 3) //remove third row { table1.Content.Remove(currentRow); break; } } } doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports System.Collections.Generic Imports Independentsoft.Office.Word Imports Independentsoft.Office.Word.Tables Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument("c:\test\input.docx") Dim tables As IList(Of Table) = doc.GetTables() Dim table1 As Table = tables(0) 'first table Dim rowCount As Integer = 0 For i As Integer = 0 To table1.Content.Count - 1 If TypeOf table1.Content(i) Is Row Then Dim currentRow As Row = DirectCast(table1.Content(i), Row) rowCount += 1 If rowCount = 3 Then 'remove third row table1.Content.Remove(currentRow) Exit For End If End If Next doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*