我有一些导出到excel的数据。在下面的代码中,当 rowText = 4.0321 时,它在 excel 中显示相同的 4.0321。但是如果 rowText = 0.00 它在 excel 报告中只显示 0。我需要它是 0.00。任何帮助,将不胜感激..
var rowText = base.GetColumnText(column, columnValue);
_writer.Write(string.Format("\"{0}\"", rowText.Replace("\"", "\"\"")));
_writer.Write(i < columns.Count - 1 ? "," : Environment.NewLine);
protected string GetColumnText(ViewColumn column, object value)
{
string text = string.Empty;
if (value != null && value != DBNull.Value)
{
var dataFormatString = column.DataFormatString;
if (string.IsNullOrEmpty(dataFormatString))
{
switch (column.ColumnType)
{
case ViewColumnType.Date:
{
dataFormatString = "{0:MM/dd/yyyy}";
}
break;
case ViewColumnType.Numeric:
{
dataFormatString = "{0:N2}";
}
break;
case ViewColumnType.Account:
{
string AccountNo = value.ToString().Trim();
if (AccountNo.Length == 8)
return string.Concat(AccountNo.Substring(0, 4), "-", AccountNo.Substring(4));
}
break;
}
}
text = !string.IsNullOrEmpty(dataFormatString) ? string.Format(dataFormatString, value) : value.ToString();
}
return text;
}