We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to do individual cell formatting in table such as font - size, italics, bold, family, color?

I was testing the current library for Aspose words to create multiple tables in my document. However I’m unable to achieve the individual cell level formatting, the CellFormat class does not provide options to set - font size, bold, italics, family. and If I try to do it with the help of DocumentBuilder it applies to all the consecutive elements(even if I use ClearFormatting() in the CellFormat class).

Can this be achieved? can you provide a code sample?


Thanks for your inquiry. Please use the following code to get desired results. Hope,this helps.

Document doc = new Document();

Table table = new Table(doc);
// Add the table to the document.

Row row = new Row(doc);
row.RowFormat.AllowBreakAcrossPages = true;

// We can now apply any auto fit settings.

// Create a cell and add it to the row
Cell cell = new Cell(doc);
cell.CellFormat.Width = 80;

// Add a paragraph to the cell as well as a new run with some text.
cell.AppendChild(new Paragraph(doc));

Run cellRun1 = new Run(doc, "Row 1, Cell 1 Text");
cellRun1.Font.Bold = true;
cellRun1.Font.Color = Color.Red;


// Add the cell to the row.

// Create a cell and add it to the row
Cell cell2 = new Cell(doc);
cell2.CellFormat.Width = 80;

// Add a paragraph to the cell as well as a new run with some text.
cell2.AppendChild(new Paragraph(doc));

Run cellRun2 = new Run(doc, "Row 1, Cell 2 Text");
cellRun2.Font.Italic = true;
cellRun2.Font.Color = Color.Blue;
cellRun2.Font.Name = "Arial";


// Add the cell to the row.


Please check attached document for your kind reference. output_19.1.zip (5.1 KB)