We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Tables in Word

Hi,

I have an existing Word doc that contains a table, currently on each row it has a bookmark start in the cell and another out of it (no idea how - legacy...). The current VBA app when deleting the bookmark deletes the row (as required by the client) - I'd like to replicate this in Aspose but as expected it didn't work - Aspose appears to follow the rules better than Word!

So my first question is, is there anyway to remove a row from a table in Word using Aspose?

Secondly, is there some nice and easy sample C# code somewhere demomstrating how to add a table to an existing document e.g. using the replace operation on a bookmark or a range?

Any guidence would be greatly appreciated.

Thanks

John

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

Thanks for your request.

1. I think that you can try using the following code.

Document doc = new Document(@"Test022\in.doc");

Row awRow = (Row)doc.Range.Bookmarks["myBookmark"].BookmarkStart.ParentNode.ParentNode.ParentNode;

awRow.Remove();

doc.Save(@"Test022\out.doc");

2. You can try using DocumentBuilder. For example see the following code.

Document doc = new Document(@"Test022\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

//Move to bookmark

builder.MoveToBookmark("test");

//build table

for (int rowIndex = 0; rowIndex < 10; rowIndex++)

{

for (int colIndex = 0; colIndex < 4; colIndex++)

{

builder.InsertCell();

builder.Write(string.Format("Cell {0} {1}", rowIndex.ToString(), colIndex.ToString()));

}

builder.EndRow();

}

builder.EndTable();

//Save document

doc.Save(@"Test022\out.doc");

I hope this could help you.

Best regards.