How can we create table in aspose word by replacing bookmark text

Hi All,

In the Aspose word document we have to replace a bookmark text with table…

I have reference to bookmark in the document…

I need to create a table with with single cell and multiple rows in the place where bookmark is present…

Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(_asposeDocument);

//Move DocumentBuildr cursor to bookmark
builder.MoveToBookmark(_currentBookMark.Name);

Aspose.Words.Tables.Table table = new Aspose.Words.Tables.Table(_asposeDocument);
builder.CurrentParagraph.AppendChild(table);
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = Aspose.Words.HeightRule.Exactly;
builder.StartTable();
builder.InsertCell();
builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
builder.Write(textToReturn);
builder.EndRow();
builder.EndTable();

Tried like above but how can we set tables margin and boder info…

Thanks in advance

Ranganatha

Hi

Thanks for your inquiry. You can use RowFormat.LertIndent to set left margin of table and CellFormat.Borders property to work with borders. I think the following code could be useful for you.

//Open document and create Documentbuilder
Document doc = new Document(@"Test118\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

//Set table formating
//Set borders
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Borders.Color = Color.Red;
//Set left indent
builder.RowFormat.LeftIndent = 100;
// etc...

//Move documentBuilder cursor to the bookmark
builder.MoveToBookmark("myBookmark");

//Insert some table
for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        builder.InsertCell();
        builder.Write("this is cell");
    }
    builder.EndRow();
}
builder.EndTable();

//Save output document
doc.Save(@"Test118\out.doc");

Best regards.