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

Free Support Forum - aspose.com

Insert a table with bookmarked cells to a table cell

Hello,
I need to insert a table with bookmarked cells to a table cell of existed word document, and insert image to the bookmarked cell, but didn’t search the answer in forums and api reference. Can you help? Thanks.

Hello

Thanks for your interest to Aspose.Words. You can try using DocumentBuilder to achieve this. Please see the following link to learn how to insert document elements using DocumentBuilder:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/inserting-document-elements.html

Also please see the following link to learn how to move the DocumentBuilder cursor to the particular table cell using MoveToCell method:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.documentbuilder.movetocell.html

Best regards,

Andrey:
Thanks for your information. Need to explain it, i want to insert table into a cell, the table inserted contain cells, and some cells are bookmarked. The page "inserting-document-elements.html", i had read it before. But it not descript how to insert a complex object, for example, a table with bookmarked cells, just the simple, inserting a string of text,a paragraph,a table,an image, and so on. So i don't know whether it can do this, and how to do. I try to use "AppendChild" to append a bookmark to cell. But it seems to not work.
Best regards.

Hello

Thanks for your inquiry. Please try using the following simple code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartTable();

// Insert a cell

builder.InsertCell();

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

builder.Writeln("This is row 1 cell 1 table 1");

// Insert a cell

builder.InsertCell();

// Insert nested table

builder.StartTable();

// Insert a cell

builder.InsertCell();

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

builder.Writeln("This is row 1 cell 1 table 2");

// Insert a cell

builder.InsertCell();

builder.Writeln("This is row 1 cell 2 table 2");

builder.EndRow();

// Apply new row formatting

builder.RowFormat.Height = 150;

builder.RowFormat.HeightRule = HeightRule.Exactly;

// Insert a cell

builder.InsertCell();

builder.Writeln("This is row 2 cell 1 table 2");

// Insert a cell

builder.InsertCell();

builder.StartBookmark("MyBookmark");

builder.Writeln("This is row 2 cell 2 table 2");

builder.EndBookmark("MyBookmark");

builder.EndRow();

builder.EndTable();

builder.EndRow();

// Apply new row formatting

builder.RowFormat.Height = 150;

builder.RowFormat.HeightRule = HeightRule.Exactly;

// Insert a cell

builder.InsertCell();

builder.Writeln("This is row 2 cell 1 table 1");

// Insert a cell

builder.InsertCell();

builder.Writeln("This is row 2 cell 2 table 1");

builder.EndRow();

builder.EndTable();

doc.Save("C:\\Temp\\out.doc", SaveFormat.Doc);

Best regards,

Thanks for your sample code. I will try it.

Best regards.