Inserting Content to a Cell

Hi,
May be this is a simple Question . I have created a table like this and i have added a cell to it.

Aspose.Words.Table table = new Aspose.Words.Table(doc);
Row row = new Row(doc);
Cell cell1 = new Cell(doc);
cell1.CellFormat.Width = 30;
row.Cells.Add(cell1);
doc.FirstSection.Body.AppendChild(table);

How can i add an Html Content to this cell
Thanks in advanve
Subeesh

Hi
Thanks for your inquiry. You can use the DocumentBuilder.InsertHtml method to insert HTML into the document. I think that you can try to use the following code.

Document doc = new Document(@"346_101920_Subeesh\in.doc");
Table table = new Aspose.Words.Table(doc);
Row row = new Row(doc);
Cell cell1 = new Cell(doc);
cell1.CellFormat.Width = 30;
row.Cells.Add(cell1);
table.Rows.Add(row);
doc.FirstSection.Body.AppendChild(table);
int tableIndex = doc.FirstSection.Body.Tables.IndexOf(table);
int rowIndex = doc.FirstSection.Body.Tables[tableIndex].Rows.IndexOf(row);
int cellIndex = doc.FirstSection.Body.Tables[tableIndex].Rows[rowIndex].Cells.IndexOf(cell1);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToCell(tableIndex, rowIndex, cellIndex, 0);
builder.InsertHtml("<b>Aspose.Words</b>");
doc.Save(@"346_101920_Subeesh\out.doc");

I hope that this will help you.
Best regards.

Hi Alexey,
Thanks for the quick reply,
The example code you have given is working correctly . But i am trying to create a table according to the data pulled from a database . This is the code snippet .

Aspose.Words.Table table = new Aspose.Words.Table(doc);
foreach (DataRow dr in dt.Rows)
{
    Row row = new Row(doc);
    Cell cell1 = new Cell(doc);
    cell1.CellFormat.Width = 30;
    Paragraph p1 = new Paragraph(doc);
    Run r1 = new Run(doc, "some html text from database");
    p1.AppendChild(r1);
    cell1.AppendChild(p1);
    row.Cells.Add(cell1);
    table.Rows.Add(row);
}
doc.FirstSection.Body.AppendChild(table);

I am getting some error when trying to find the index of the row and cell from the loop , is there any other way to insert the html content , other than using the document builder.

Hi
Thanks for additional information. You can try to use the following code to solve this problem.

Table table = new Aspose.Words.Table(doc);
Row row = new Row(doc);
Cell cell1 = new Cell(doc);
cell1.CellFormat.Width = 100;
//create document
Document doc1 = new Document();
DocumentBuilder builder = new DocumentBuilder(doc1);
//insert HTML
builder.InsertHtml("<b>Aspose.Words</b><br>Aspose.Words");
//insert HTML into the cell
foreach (Node node in doc1.FirstSection.Body.ChildNodes)
{
    cell1.AppendChild(doc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting));
}
row.Cells.Add(cell1);
table.Rows.Add(row);
doc.FirstSection.Body.AppendChild(table);

I hope that this will help you.
Best regards.

Hi,
Thanks for the reply , but i couldnt check the result because , the output was truncated as i am using the evaluation version .
Is there any way that i can test the features of the product before i purchase it . We are now using another product from Aspose , it is Aspose PDF . We could test all the features of the product before we buy it with a watermark from aspose.
Subeesh

Hi
Thanks for your inquiry. If you want to test Aspose.Words without evaluation version limitations, you can also request a 30-Day Temporary License. Please refer to How to get a Temporary License?
Best regards.

Hi,
Thank you for your reply . I got a temporary licence and your code works…
Subeesh