Infragistics.Excel–Set the format to dollars on a cell, column or row.

Posted by Blake on 1/27/2012
)

These extension methods will allow you to easily format a column for dollars. These can be altered to use any format that you can create in Excel (and then copy and paste here). I do this a lot when creating spreadsheets and these save me time trying to remember the impossible to remember FormatString.

            ''' <summary>
        ''' Formats the specified cell as dollars.
        ''' </summary>
        ''' <param name="cell"></param>
        ''' <remarks></remarks>
        <Extension()> _
        Public Sub SetFormatDollars(ByVal cell As WorksheetCell)
            cell.CellFormat.FormatString = """$""#,##0.00_);(""$""#,##0.00)"
        End Sub
        ''' <summary>
        ''' Formats the specified column as dollars.
        ''' </summary>
        ''' <param name="column"></param>
        ''' <remarks></remarks>
        <Extension()> _
        Public Sub SetFormatDollars(ByVal column As WorksheetColumn)
            column.CellFormat.FormatString = """$""#,##0.00_);(""$""#,##0.00)"
        End Sub
        ''' <summary>
        ''' Formats the specified row as dollars.
        ''' </summary>
        ''' <param name="row"></param>
        ''' <remarks></remarks>
        <Extension()> _
        Public Sub SetFormatDollars(ByVal row As WorksheetRow)
            row.CellFormat.FormatString = """$""#,##0.00_);(""$""#,##0.00)"
        End Sub