Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
875
Format cell to 2 decimal places
posted

Hello,

I am having to manually export an Infragistics WebGrid to excel (using the .Export method does not work in my case as there are some additional things that must be added/removed from the export).

Everything is exporting fine, except for the format... I would like to format the numbers in the grid cells to 2 decimal places if it already contains a decimal place, otherwise I would like to use no decimal places.

I have the following and the output is always the same, if there are no decimal places, none appear (which is great), but otherwise it uses the same amount of decimal places that are in the grid (so, up to 16 decimal places in some cases!).

Dim excelWorkbook As Workbook
Dim exportRowNumber As Integer
Dim exportCellIndex As Integer

...

excelWorkbook.WindowOptions.SelectedWorksheet.Rows(exportRowNumber).Cells(exportCellIndex).Value = <cell from the grid>.Text
excelWorkbook.WindowOptions.SelectedWorksheet.Rows(exportRowNumber).Cells(exportCellIndex).CellFormat.FormatString = "##.##"

Why is the format string that I'm setting not being applied to the cell in Excel?