Commit f50a81db by guanzhenshan

增加适配表格的公式值

parent 0e31cc62
......@@ -136,7 +136,7 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
jsondata = Newtonsoft.Json.JsonConvert.SerializeObject(item),
month = month,
platformtype = platform,
website = website,
website = website??"",
createuser = "页面上传",
datatype = 1,
datatypename = "物流账单",
......
......@@ -144,16 +144,18 @@ namespace Bailun.DC.Web.Base
if (cell == null) { dataRow[j] = ""; }
else
{
switch (cell.CellType)
{
case CellType.Blank: dataRow[j] = ""; break;
case CellType.Numeric:
short format = cell.CellStyle.DataFormat;
if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) dataRow[j] = cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss");
else dataRow[j] = cell.NumericCellValue;
break;
case CellType.String: dataRow[j] = cell.StringCellValue; break;
}
dataRow[j] = GetCellValue(cell);
//switch (cell.CellType)
//{
// case CellType.Blank: dataRow[j] = ""; break;
// case CellType.Numeric:
// short format = cell.CellStyle.DataFormat;
// if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) dataRow[j] = cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss");
// else dataRow[j] = cell.NumericCellValue;
// break;
// case CellType.String: dataRow[j] = cell.StringCellValue; break;
//}
}
}
dataTable.Rows.Add(dataRow);
......@@ -182,7 +184,43 @@ namespace Bailun.DC.Web.Base
}
}
public static string GetCellValue(ICell cell)
{
if (cell == null)
return string.Empty;
switch (cell.CellType)
{
case CellType.Blank:
return string.Empty;
case CellType.Boolean:
return cell.BooleanCellValue.ToString();
case CellType.Error:
return cell.ErrorCellValue.ToString();
case CellType.Numeric:
short format = cell.CellStyle.DataFormat;
if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) return cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss");
return cell.NumericCellValue.ToString();
case CellType.Unknown:
default:
return cell.ToString();
case CellType.String:
return cell.StringCellValue;
case CellType.Formula:
try
{
HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
e.EvaluateInCell(cell);
return cell.ToString();
}
catch
{
return cell.NumericCellValue.ToString();
}
}
}
#endregion
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment