Hi
I’m trying to create a table with an other table inside. I add the sub-table in a cell to be able to add it to a row of the main table.I don’t want any spaces beetween the two table, as if it was one table with splitted cells.It is working, except for the inner top and bottom padding. Left and right are OK.
public MemoryStream ExportWord()
{
// Set the license.
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(ASPOSE_WORDS_LICENSE_PATH);
Document document = new Document();
Section section = document.FirstSection;
section.PageSetup.Orientation = Orientation.Portrait;
section.PageSetup.PaperSize = PaperSize.A4;
Body body = section.Body;
Table mainTable = new Table(document);
Row mainRow = new Row(document);
mainRow.AppendChild(BuildCell("cell_left", document));
Table subTable = new Table(document);
Row subRow1 = new Row(document);
subRow1.AppendChild(BuildCell("row_1_cell_1", document));
subRow1.AppendChild(BuildCell("row_1_cell_2", document));
subTable.AppendChild(subRow1);
Row subRow2 = new Row(document);
subRow2.AppendChild(BuildCell("row_2_cell_1", document));
subRow2.AppendChild(BuildCell("row_2_cell_2", document));
subTable.AppendChild(subRow2);
Cell container = new Cell(document);
container.AppendChild(subTable);
container.CellFormat.BottomPadding = 0.0;
container.CellFormat.LeftPadding = 0.0;
container.CellFormat.TopPadding = 0.0;
container.CellFormat.RightPadding = 0.0;
mainRow.AppendChild(container);
mainTable.AppendChild(mainRow);
body.AppendChild(mainTable);
mainTable.BottomPadding = 0.0;
mainTable.LeftPadding = 0.0;
mainTable.TopPadding = 0.0;
mainTable.RightPadding = 0.0;
// Save word document as stream ...
document.UpdateTableLayout();
MemoryStream stream = new MemoryStream();
document.Save(stream, SaveFormat.Docx);
// ... and return it
return stream;
}
private Cell BuildCell(string content, Document document)
{
Run run = new Run(document);
run.Text = content;
Paragraph paragraph = new Paragraph(document);
paragraph.AppendChild(run);
Cell cell = new Cell(document);
cell.AppendChild(paragraph);
cell.CellFormat.BottomPadding = 4.0;
cell.CellFormat.LeftPadding = 4.0;
cell.CellFormat.TopPadding = 4.0;
cell.CellFormat.RightPadding = 4.0;
return cell;
}
How can I remove those bottom and top spaces ?(see docx attachment)
Thanks
Adrian