Commit f50a81db by guanzhenshan

增加适配表格的公式值

parent 0e31cc62
...@@ -136,7 +136,7 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers ...@@ -136,7 +136,7 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
jsondata = Newtonsoft.Json.JsonConvert.SerializeObject(item), jsondata = Newtonsoft.Json.JsonConvert.SerializeObject(item),
month = month, month = month,
platformtype = platform, platformtype = platform,
website = website, website = website??"",
createuser = "页面上传", createuser = "页面上传",
datatype = 1, datatype = 1,
datatypename = "物流账单", datatypename = "物流账单",
......
...@@ -144,16 +144,18 @@ namespace Bailun.DC.Web.Base ...@@ -144,16 +144,18 @@ namespace Bailun.DC.Web.Base
if (cell == null) { dataRow[j] = ""; } if (cell == null) { dataRow[j] = ""; }
else else
{ {
switch (cell.CellType) dataRow[j] = GetCellValue(cell);
{
case CellType.Blank: dataRow[j] = ""; break; //switch (cell.CellType)
case CellType.Numeric: //{
short format = cell.CellStyle.DataFormat; // case CellType.Blank: dataRow[j] = ""; break;
if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) dataRow[j] = cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss"); // case CellType.Numeric:
else dataRow[j] = cell.NumericCellValue; // short format = cell.CellStyle.DataFormat;
break; // if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) dataRow[j] = cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss");
case CellType.String: dataRow[j] = cell.StringCellValue; break; // else dataRow[j] = cell.NumericCellValue;
} // break;
// case CellType.String: dataRow[j] = cell.StringCellValue; break;
//}
} }
} }
dataTable.Rows.Add(dataRow); dataTable.Rows.Add(dataRow);
...@@ -182,7 +184,43 @@ namespace Bailun.DC.Web.Base ...@@ -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 #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