I am trying to export a Ultra Grid to excel document. Which I do successfully with:
uexpAssetMaint.Export(ugrdAScheduleMaint) 'ugrdAScheduleMaint as my grid
When it displays in Excel I am getting an error message saying that my grid is being exported as text do I want to convert it to a number. Which is all fine, although I would like it if the end user could prevent from going through this extra step. I was thinking about passing it as a value, but don't know how to keep the format, and not mess my grid. Any ideas?
The ExcelExporter has a number of events which fire during the export process. When a number of our grids are exported deliberately for use in Excel we had the same issue.
To fix this, in the RowExported event...You can reference a cell by index etc and CType(...,Double) etc and the value will be a number when opened in Excel. Example: Protected Sub UltraWebGridExcelExporter1_RowExported(ByVal sender As Object, ByVal e As ExcelExport.RowExportedEventArgs) Handles UltraWebGridExcelExporter1.RowExported With e.CurrentWorksheet.Rows(e.CurrentRowIndex) ' make the cells double value... .Cells(0).Value = Ctype(.Cells(0).Value, Double) .Cells(1).Value = Ctype(.Cells(1).Value, Double) End With End Sub
Also, you can set the cell's format...just like in Excel...this can definitely be useful! example:
' Get access to the cell in whatever event you want...' -- make the cell always have 1 decimal place but as many as needed etcCell.CellFormat.FormatString = "0.0###################"