Version

Copying a Cell’s Format (Infragistics Excel Engine)

Cells can have different formatting, including background color, format string, and font style. If you need a cell to have the same format as a previously formatted cell, instead of individually setting each option exposed by the WorksheetCell object’s CellFormat property, you can call the CellFormat object’s SetFormatting method and pass it a CellFormat object to copy. This will copy every format setting from the first cell to the second cell. You can also do this for a row, merged cell region, or column.

The following code shows you how to copy the format of the 2nd column to the 4th column.

In Visual Basic:

Imports Infragistics.Documents.Excel
...
'Format 2nd column
worksheet1.Columns(1).CellFormat.Fill = _
    CellFill.CreateSolidFill(System.Windows.Media.Colors.Green)
worksheet1.Columns(1).CellFormat.Font.Bold = ExcelDefaultableBoolean.True
'Copy format of 2nd column to 4th column
worksheet1.Columns(3).CellFormat.SetFormatting(worksheet1.Columns(1).CellFormat)

In C#:

using Infragistics.Documents.Excel;
...
//Format 2nd column
worksheet1.Columns[1].CellFormat.Fill =
    CellFill.CreateSolidFill(System.Windows.Media.Colors.Green);
worksheet1.Columns[1].CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
//Copy format of 2nd column to 4th column
worksheet1.Columns[3].CellFormat.SetFormatting(worksheet1.Columns[1].CellFormat);