1
votes

I have a .net application which generates excel from simple string variable where every cell gets its value like this:

For iCol = 0 To Cols.Rows.Count - 1
                str &= Trim(Cols.Rows(iCol)("capt")) & vbTab
            Next

I am looking for a way to change cell background and/or set text bold via excel formula.

Something like

str &= "=<b>"
str &= Trim(Cols.Rows(iCol)("capt"))
str &= "</b>"

or

 str &= "=<p bgcolor=" + "color" + ">"
 str &= Trim(Cols.Rows(iCol)("capt"))
 str &= "</p>"

Macro or conditional-formatting is not an option.

1

1 Answers

2
votes

You're looking for the Range.Font and Range.Interior properties.

For iCol = 0 To Cols.Rows.Count - 1
    str &= Trim(Cols.Rows(iCol)("capt")) & vbTab
    Cells(row, iCol).Font.Bold = True
    Cells(row, iCol).Interior.Color = ColorConstants.vbCyan
Next