facebooktwittermenuarrow-up

GemBox Support Forum

Adressing existing tables and deleting certain rows

Hi there,

I’d like to modify an existing table (called table01 in this post) within a document. As table01 get referenced by other tables that should get information about certain fields in table01, I do not want to create table01 form the scratch via .net. But I’d like to remove single lines of table01 if necessary.

So my questions are:

  1. Is it possible to get al list of all tables within my document, select a single table and remove indexed rows (e.g. row 2, 5, 7-9 and 14) from this table?

  2. If adressing a single row within a table is not possible, I can create a named bookmark for each row in table01 (e.g. by using Word). How do I select these bookmarks via gembox.document and delete the bookmarked table row?

I can provide a dummy document if necessary.

Best regards

Dirk

Hi Dirk,

Here is a small sample code that you can try:

var document = DocumentModel.Load("input.docx");

// Get all tables.
var tables = document.GetChildElements(true, ElementType.Table).Cast<Table>();

// Select the targeted table using title information.
// This information can be set from: "Microsoft Word" -> "Table Properties" -> "Alt Text" -> "Title"
var table = tables.First(t => t.Metadata.Title == "table01");

// Remove second row.
table.Rows.RemoveAt(1);

// Remove the fifth row, which is now the fourth row because we removed one row before it.
table.Rows.RemoveAt(3);

// ...

document.Save("output.docx");

If the problem remains, please send us your input document and the desired output document that you would like to get.
I’ll compare those two and send you a code with which you’ll be able to achieve the required task.

Regards,
Mario

Dear Mario,

again thank you very much for your code example.

I have to convert it to vb.net and add

Imports GemBox.Document.Tables

at the beginning to make the compiler know the Cast(of Table)() element. And know I can delete rows from my table.

Great job.

Thank you so much.

Dirk