When I export some data to excel, and open it with excel 2003, every number cell has a green triangle in the top left corner and has the error "Number stored as text". How do I specify that the cell contains a number?
The way I'm adding data to the excel file is:
Workbook workbook = new Workbook();workbook.Worksheets.Clear();Worksheet sheet = workbook.Worksheets.Add("Test");sheet.Rows[0].Cells[0].Value = "String"sheet.Rows[0].Cells[1].Value = 0.0;BIFF8Writer.WriteWorkbookToFile(workbook, filename);
Thanks.
-Nick
Hi Joseph,
If the data in the grid is type double, then the UltraGridExcelExporter will export it to Excel as a double. You don't have to do anything.
If the data in your Excel sheet is the wrong type, then it's either the wrong type in the grid (maybe you are storing it in your data source as a string) or else something in your code is exporting it incorrectly.
If you are storing numeric data as strings, that will cause all sorts of problems with filtering, sorting, and exporting. So the best thing to do would be to store the data as a double. But if you can't do that, you could handle the CellExported event and write it to the cell directly.
How do you set the export datatype when the grid is bound to a datatable that has double dataype columns.
You just need to specity the data type in the export started event:
Private Sub UltraGridExcelExporter1_ExportStarted(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs) Handles UltraGridExcelExporter1.ExportStarted ' Add new row count column e.Layout.Override.AllowAddNew = AllowAddNew.Yes e.Layout.Bands(0).Columns.Insert(0, "count").Header.Caption = "[row #]" e.Layout.Bands(0).Columns(0).Width = 40 e.Layout.Bands(0).Columns(0).DataType = GetType(Integer)End Sub
and then add the row #:
Private Sub UltraGridExcelExporter1_RowExporting(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.RowExportingEventArgs) Handles UltraGridExcelExporter1.RowExporting ' Add row # e.GridRow.Cells("count").Value = e.CurrentRowIndex e.GridRow.Cells("count").Appearance.TextHAlign = HAlign.CenterEnd Sub
Hi Nick,
I just ran the code you have here and it works fine for me. You should not have to do anything special - numbers should be exported as numbers.
What version of the controls are you using? Perhaps you need to get the latest service release? How to get the latest service release - Infragistics Community