我正在尝试将格式化数据表设置为 Excel 工作表。
简单地说:
ws.InsertDataTable(myDatatable,
new InsertDataTableOptions()
{
ColumnHeaders = false,
StartRow = 5
});
但是 myDatatable 单元格主要包含数值。 当我通过 Gembox 电子表格将数据表插入 Excel 时,许多单元格收到“数字存储为文本”警告。
我不想禁用此警告,但我想应用“转换为数字”,就像我们在 Excel 中所做的那样。
最佳答案
我认为 myDatatable
中的那些数值是 string
类型,对吗?
在这种情况下,请尝试以下操作:
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);
关于c# - Gembox 电子表格 : Is it possible to apply "Convert To Number" for the cells with warning?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37675561/