Free Support Forum - aspose.com

Highlight selected rows and delete it

Hi:

Is there a way at to highlight the number of rows and do a delete all those rows? Currently this is how it's done in the Word Object.

WordObj.Selection.MoveDown(Unit:=wdParagraph, Count:=3)
WordObj.Selection.MoveRight(Unit:=wdCell, Count:=1)
WordObj.Selection.MoveDown(Unit:=wdParagraph, Count:=8, Extend:=wdExtend)
WordObj.Selection.Rows.Delete()

Also, since there is no MoveUp/MoveDown in Aspose.Words how could the following be done?

WordObj.Selection.MoveUp(Unit:=wdLine, Count:=2)
WordObj.Selection.SelectRow()
WordObj.Selection.Copy()
WordObj.Selection.MoveDown(Unit:=wdLine, Count:=2)
WordObj.Selection.Paste()

Do I just have to define the exact row to clone? Any advice/suggestions or even better code sample would be great. Thanks for your help. By the way, I'm using VB .NET.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can remove table rows using the following code:

'Get table

Dim tab as Table = doc.FirstSection.Body.Tables(0))

'Remove row from table

TAB.Rows(5).Remove()

You should clone existing row and use InsertAfter method for inserting this row after original row.

'Open document

Dim doc As Document = New Document("test.doc")

'Get table from the second section of document

Dim myTable As Table = doc.Sections(0).Body.Tables(0)

'Get row of table (its idex is 16)

Dim myRow As Row = myTable.Rows(16)

'Clone row

Dim newRow As Row = CType(myRow.Clone(True), Row)

myTable.InsertAfter(newRow, myRow refRow)

'Save document

doc.Save("out.doc")

Hope this helps.

Best regards.

Thanks for your help!