Table cell size when table within table cell

Hi,
I am trying to reproduce the table below in Aspose.Words 6.0.0.0 It must appear in a TextBox and may have paragraphs of text before/after in the TextBox. I tried to create this by creating a table inside a table. The outer table has a red cell border. The inner table only puts a blue border around the first cell.

1,1 1,2
2,1 2,2

I am having a few issues at the moment. My code is attached. I have used multiple document builders to render the tables in an attempt to stop them interfering with each other.

  1. When I set a cell to have a blue border, every cell after this is blue.
  2. When I add a table inside another table’s cell, every cell in that table is the same width as the original cell. I am trying to get the entire inner table the width of the original cell.
  3. When there is an inner table, half doesn’t appear. Even when I expand the TextBox it cannot be seen.
  4. The border of the outer cell is not displayed when there is an inner table.

Thank you for your time. Any guidance would be appreciated.

Hi
Thanks for your request. Could you please create such table using MS Word and attach the document here. This will help me to create sample code for you.
Best regards.

Hi,
Thanks for your quick reply. I have created the table in the attached word doc.

Hi
Thank you for additional information. Please try using the following code:

// Create Document and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create TextBox shape and insert it into the document
Shape textBox = new Shape(doc, ShapeType.TextBox);
// Specify size of text box
textBox.Height = 125;
textBox.Width = 200;
// Create paragraph and insert it into the textbox
Paragraph par = new Paragraph(doc);
textBox.AppendChild(par);
// Insert textbox into the document
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
// Move DocumentBuilder cursor to paragraph inserted into the shape
builder.MoveTo(par);
// Insert some text
builder.Writeln("text before table");
// Insert empty line
builder.Writeln();
// Start table
Table t0 = builder.StartTable();
// Insert one cell into the table
builder.InsertCell();
// Specify borders formating
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Borders.Color = Color.Red;
// Specify cell paddings
builder.CellFormat.TopPadding = 2.85;
builder.CellFormat.BottomPadding = 2.85;
builder.CellFormat.LeftPadding = 2.85;
builder.CellFormat.RightPadding = 2.85;
builder.EndRow();
builder.EndTable();
// Insert one more empty paragraph
builder.Writeln();
// and some text
builder.Write("text after table");
// Now we can build nested table.
t0.FirstRow.FirstCell.EnsureMinimum();
// Move DocumentBuilder cursor into the table
builder.MoveTo(t0.FirstRow.FirstCell.FirstParagraph);
// Build nested table
builder.InsertCell();
builder.Write("1,1");
// Specify borders formating
builder.CellFormat.Borders.Color = Color.Blue;
builder.InsertCell();
builder.Write("1,2");
// Reset borders
builder.CellFormat.Borders.LineStyle = LineStyle.None;
builder.EndRow();
builder.InsertCell();
builder.Write("2,1");
builder.InsertCell();
builder.Write("2,2");
builder.EndRow();
builder.EndTable();
doc.Save(@"Test095\out.doc");

Hope this helps.
Best regards.

Hi,
Thanks for your code. It was a great help. My sizing problem no longer occurs (in my code the second table cells were too big). I think it was something to do with the timing of when I completed the first table and also not moving the document builder when I should have.
Thanks.