2

I am trying set my formatted datatable to an excel worksheet.

Simply :

ws.InsertDataTable(myDatatable,
new InsertDataTableOptions()
{
    ColumnHeaders = false,
    StartRow = 5
});

But myDatatable cells contains numeric values mostly. And when I insert my datatable into excel via Gembox Spreadsheet, many of the cells got "Number Stored as Text" warning.

I don't want to disable this warning, but I want to apply a "Convert To Number" as we do in excel.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jean
  • 524
  • 4
  • 21

1 Answers1

2

I presume that those numeric values in myDatatable are of string type, am I right?
In that case try the following:

var options = new InsertDataTableOptions()
{
    ColumnHeaders = false,
    StartRow = 5
};

options.DataTableCellToExcelCellConverting += (s, e) =>
{
    string textNumber = e.DataTableValue as string;
    double number;
    if (textNumber != null && double.TryParse(textNumber, out number))
        e.ExcelCellValue = number;
};

ws.InsertDataTable(myDatatable, options);
Mario Z
  • 4,328
  • 2
  • 24
  • 38