I have this code. How do I center text in a table cell? I want to center “Some Text” within the cell.
var stream = new MemoryStream();
var license = new License();
license.SetLicense("Aspose.Total.Product.Family.lic");
var doc = new Document("MyReport.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("TableBookmark");
Table table = builder.StartTable();
table.ClearBorders();
Cell cell = builder.InsertCell();
builder.Write("Some Text");
builder.EndRow();
builder.EndTable();
Hi Greg,
Thanks for your query. Please use the ParagraphAlignment.Center to align the text as center. Please use the following code snippet for your requirement and let us know if you have any more queries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("Text in another cell.");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.Write("Text in another cell.");
builder.EndRow();
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.Write("Text in another cell.");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Justify;
builder.Write("Text in another cell.");
builder.EndRow();
table.ClearBorders();
doc.Save(MyDir + "AsposeOut.docx");