How can I bold the fonts of a specific row or cell in an Excel worksheet with C#? How can I bold the fonts of a specific row or cell in an Excel worksheet with C#? windows windows

How can I bold the fonts of a specific row or cell in an Excel worksheet with C#?


How to Bold entire row 10 example:

workSheet.Cells[10, 1].EntireRow.Font.Bold = true;    

More formally:

Microsoft.Office.Interop.Excel.Range rng = workSheet.Cells[10, 1] as Xl.Range;rng.EntireRow.Font.Bold = true;

How to Bold Specific Cell 'A10' for example:

workSheet.Cells[10, 1].Font.Bold = true;

Little more formal:

int row = 1;int column = 1;  /// 1 = 'A' in ExcelMicrosoft.Office.Interop.Excel.Range rng = workSheet.Cells[row, column] as Xl.Range;rng.Font.Bold = true;


Your question is a little unclear...as the part that you indicate you want to bold in Excel is a DataGridView in the import from word method. Do you maybe want to bold the first row in the excel document?

using xl = Microsoft.Office.Interop.Excel;xl.Range rng = (xl.Range)xlWorkSheet.Rows[0];rng.Font.Bold = true;

Simple as that!

HTH,Z


I have done this in a project a long time ago. The code given below write a whole rows bold with specific column names and all of these columns are written in bold format.

private void WriteColumnHeaders(DataColumnCollection columnCollection, int row, int column)    {        // row represent particular row you want to bold its content.        for (i = 0; i < columnCollection.Count; i++)        {            DataColumn col = columnCollection[i];            xlWorkSheet.Cells[row, column + i + 1] = col.Caption;            // Some Font Styles            xlWorkSheet.Cells[row, column + i + 1].Style.Font.Bold = true;            xlWorkSheet.Cells[row, column + i + 1].Interior.Color = Color.FromArgb(192, 192, 192);            //xlWorkSheet.Columns[i + 1].ColumnWidth = xlWorkSheet.Columns[i+1].ColumnWidth + 10;        }    }

You must pass value of row 0 so that first row of your excel sheets have column headers with bold font size. Just change DataColumnCollection to your columns name and change col.Caption to specific column name.

Alternate

You may do this to cell of excel sheet you want bold.

xlWorkSheet.Cells[row, column].Style.Font.Bold = true;