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

Free Support Forum - aspose.com

Cannot set font to be bold on the first line of the table

hi - I have not been able to set the font of the first line (in blue background) to be bold.

public void InsertAt(string bookMark, System.Data.DataTable aTable, System.Drawing.Font defaultFont, bool lineAtBottom)
{
    if (mBuilder == null) throw new Exception("Null builder");
    if (bookMark == string.Empty) throw new Exception("No bookmark found in InsertAt");
    if (aTable != null && aTable.Rows.Count > 0)
    {
        mBuilder.MoveToBookmark(bookMark);
        OPWord.Tables.Table outputTable = mBuilder.StartTable();
        // outputTable.ClearBorders();
        int nRow = 0;
        mBuilder.ParagraphFormat.Style.Font.Name = defaultFont.Name;
        mBuilder.RowFormat.Height = 18.4;
        mBuilder.RowFormat.HeightRule = OPWord.HeightRule.Exactly;
        foreach (System.Data.DataRow aRow in aTable.Rows)
        {
            nRow++;
            for (int j = 0; j
            {
                // mBuilder.CellFormat.Width = 30.0;
                OPWord.Tables.Cell aCell = mBuilder.InsertCell();
                aCell.CellFormat.ClearFormatting();
                aCell.CellFormat.Borders.ClearFormatting();
                aCell.CellFormat.PreferredWidth = OPWord.Tables.PreferredWidth.FromPercent((double)(100.0 / aTable.Columns.Count));
                aCell.FirstParagraph.ParagraphFormat.Alignment = OPWord.ParagraphAlignment.Center;
                aCell.CellFormat.VerticalAlignment = OPWord.Tables.CellVerticalAlignment.Center;
                if (nRow == aTable.Rows.Count && lineAtBottom)
                {
                    aCell.CellFormat.Borders.Bottom.LineStyle = OPWord.LineStyle.Thick;
                    aCell.CellFormat.Borders.Bottom.LineWidth = 1.5;
                }
                if (nRow == 1)
                {
                    aCell.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(0, 51, 153);
                    aCell.FirstParagraph.ParagraphFormat.Style.Font.Bold = true;
                }
                else
                {
                    aCell.FirstParagraph.ParagraphFormat.Style.Font.Bold = false;
                }
                aCell.FirstParagraph.AppendChild(new Aspose.Words.Run(mDoc, aRow[j].ToString()));
                // mBuilder.Write(aRow[j].ToString());
            }
            mBuilder.EndRow();
        }
        // outputTable.PreferredWidth = OPWord.Tables.PreferredWidth.FromPoints(450);
        mBuilder.EndTable();
    }
}

Hi Philip,

Thanks for your inquiry. Current font formatting is represented by a Font object returned by the DocumentBuilder.Font property. The Font class contains a wide variety of the font properties possible in Microsoft Word. I suggest you please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/applying-formatting/

Please check the highlighted lines of code in following code example. This code example bold the text of first row of table. Hope this helps you. Please let us now if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
// Insert a cell
builder.InsertCell();
table.PreferredWidth = PreferredWidth.FromPercent(100);
builder.Font.Bold = true;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Write("This is row 1 cell 1");
// Insert a cell
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
builder.Font.Bold = false;
// Insert a cell
builder.InsertCell();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
builder.Writeln("This is row 2 cell 1");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
doc.Save(MyDir + "Out.docx");