我正在尝试将数据导出到Excel并且当前正在使用此代码源:http://www.codeproject.com/Tips/659666/Export-very-large-data-to-Excel-file
我从firebird数据库获取数据,其中一半字段是小数。问题是当我将数据导出到Excel时,我所有的十进制值(如123,45)将视为Excel中的文本,但是0或200之类的值将被视为数字。
我尝试过像这样解析我的价值观:
public static bool isDecimal(string s)
{
NumberStyles style;
CultureInfo culture;
decimal number;
style = NumberStyles.AllowDecimalPoint | NumberStyles.Float;
culture = CultureInfo.CurrentCulture;
if (Decimal.TryParse(s, style, culture, out number))
return true;
else
return false;
}
但是当我写入Excel时使用上述功能时,它无法正常工作:
foreach (DataRow dsrow in ResultsData.Rows)
{
DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
foreach (DataColumn col in ResultsData.Columns)
{
DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
if (isDecimal(dsrow[col].ToString()))
{
cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.Number;
}
else
{
cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
}
cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[col].ToString());
newRow.AppendChild(cell);
}
sheetData.AppendChild(newRow);
}
P.S。我的国家使用俄罗斯文化信息(123,45)而不是(123.45)
答案 0 :(得分:0)
我想说这是电子表格的文化 - 它将123,45识别为数字。有没有办法改变<option value="span class=" priority-data-low"="">Low</option>
的文化?
如果没有,也许你可以替换&#39;,&#39;用&#39;。&#39;对于适用于RU的导入和格式列?
我想说这是电子表格的文化 - 它将123,45识别为数字。有没有办法改变sheetData
的文化?
如果没有,也许你可以替换&#39;,&#39;用&#39;。&#39;对于适用于RU的导入和格式列? e.g。
sheetData