Commit 313858af by lcx

抽取数据为数值,录取获取数据时异常

parent a5f1dd1c
......@@ -300,7 +300,7 @@ public HandsonTable GetCollectData(int userId, int allotId, string sheetName)
if (sheet == null)
throw new PerformanceException("找不到当前SHEET页信息");
var headers = perforImheaderRepository.GetEntities(w => w.SheetID == sheet.ID).OrderBy(w => w.PointCell);
var headers = perforImheaderRepository.GetEntities(w => w.SheetID == sheet.ID)?.OrderBy(w => w.PointCell);
if (headers == null || !headers.Any())
throw new PerformanceException("SHEET页没有有效列头");
var cols = headers.Select(w => w.CellValue).ToArray();
......
......@@ -1740,16 +1740,22 @@ private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<NewE
if (newCell == null) continue;
var value = deptData.FirstOrDefault(t => t.Category == headName)?.Value;
if (!value.HasValue || value == 0)
{
newCell.SetCellType(CellType.String);
var oldvalue = ConvertHelper.To<decimal>(newCell.StringCellValue);
if (oldvalue > 0) continue;
}
if (isIncom)
{
value = value == 0 ? null : value;
OutToExcelCell(newCell, value);
OutToExcelCell<decimal>(newCell, value);
newCell.CellStyle = style;
}
else if (newCell.CellType != CellType.Formula)
{
value = value == 0 ? null : value;
OutToExcelCell(newCell, value);
OutToExcelCell<decimal>(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -1807,15 +1813,21 @@ private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<NewE
}
else
{
celldata = allExtract.FirstOrDefault(t => t.Department == department && t.Category == headName);
var value = allExtract.FirstOrDefault(t => t.Department == department && t.Category == headName)?.Value;
if (!value.HasValue || value == 0)
{
newCell.SetCellType(CellType.String);
var oldvalue = ConvertHelper.To<decimal>(newCell.StringCellValue);
if (oldvalue > 0) continue;
}
if (isIncom)
{
OutToExcelCell(newCell, celldata?.Value);
OutToExcelCell<decimal>(newCell, value);
newCell.CellStyle = style;
}
else if (header != null && header.Contains(headName))
{
OutToExcelCell(newCell, celldata?.Value);
OutToExcelCell<decimal>(newCell, value);
newCell.CellStyle = style;
}
}
......@@ -1912,7 +1924,7 @@ private void WriteWorkData(ISheet sheet, IPerSheetDataRead sheetRead, List<NewEx
{
var extract = deptData.FirstOrDefault(t => t.Category == headName);
var value = extract?.Value == 0 ? null : extract?.Value;
OutToExcelCell(newCell, value);
OutToExcelCell<decimal>(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -1956,7 +1968,7 @@ private void WriteWorkData(ISheet sheet, IPerSheetDataRead sheetRead, List<NewEx
else
{
var extract = allExtract.FirstOrDefault(t => t.Department == department && t.Category == headName);
OutToExcelCell(newCell, extract?.Value);
OutToExcelCell<decimal>(newCell, extract?.Value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -2095,13 +2107,13 @@ private void WriteCollectData(ISheet sheet, IPerSheetDataRead sheetRead, List<co
if (isIncom)
{
var cellvalue = value == "0" ? null : ConvertHelper.To<decimal?>(value);
OutToExcelCell(newCell, cellvalue);
OutToExcelCell<decimal>(newCell, cellvalue);
newCell.CellStyle = style;
}
else if (newCell.CellType != CellType.Formula)
{
var cellvalue = value == "0" ? null : ConvertHelper.To<decimal?>(value);
OutToExcelCell(newCell, cellvalue);
OutToExcelCell<decimal>(newCell, cellvalue);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -2149,12 +2161,12 @@ private void WriteCollectData(ISheet sheet, IPerSheetDataRead sheetRead, List<co
var celldata = data.FirstOrDefault(t => t.Department == department.Department && t.AccountingUnitDoctor == department.AccountingUnitDoctor && t.AccountingUnitNurse == department.AccountingUnitNurse && t.AccountingUnitTechnician == department.AccountingUnitTechnician && t.TypeName == headName);
if (isIncom)
{
OutToExcelCell(newCell, celldata?.CellValue);
OutToExcelCell<decimal>(newCell, celldata?.CellValue);
newCell.CellStyle = style;
}
else if (header != null && header.Contains(headName))
{
OutToExcelCell(newCell, celldata?.CellValue);
OutToExcelCell<decimal>(newCell, celldata?.CellValue);
newCell.CellStyle = style;
}
}
......@@ -2239,7 +2251,7 @@ private void WriteCollectWorkData(ISheet sheet, IPerSheetDataRead sheetRead, Lis
{
var extract = deptData.FirstOrDefault(t => t.TypeName == headName);
var value = extract?.CellValue == "0" ? null : extract?.CellValue;
OutToExcelCell(newCell, value);
OutToExcelCell<decimal>(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -2280,7 +2292,7 @@ private void WriteCollectWorkData(ISheet sheet, IPerSheetDataRead sheetRead, Lis
else
{
var extract = celldata.FirstOrDefault(t => t.Department == department && t.TypeName == headName);
OutToExcelCell(newCell, extract?.CellValue);
OutToExcelCell<decimal>(newCell, extract?.CellValue);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
......@@ -2372,6 +2384,56 @@ public void OutToExcelCell(ICell cell, object obj)
}
}
public void OutToExcelCell<T>(ICell cell, object obj, T defaultValue = default)
{
string value = obj?.ToString() ?? "";
try
{
var type = defaultValue.GetType();
switch (type.ToString())
{
case "System.String"://字符串类型
cell.SetCellValue(value);
break;
case "System.DateTime"://日期类型
DateTime dateV;
DateTime.TryParse(value, out dateV);
cell.SetCellValue(dateV.ToString("yyyy/M/d"));
break;
case "System.Boolean"://布尔型
bool boolV = false;
bool.TryParse(value, out boolV);
cell.SetCellValue(boolV);
break;
case "System.Int16"://整型
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = 0;
int.TryParse(value, out intV);
cell.SetCellValue(intV);
break;
case "System.Decimal"://浮点型
case "System.Double":
double doubV = 0;
double.TryParse(value, out doubV);
cell.SetCellValue(doubV);
break;
case "System.DBNull"://空值处理
cell.SetCellValue("");
break;
default:
cell.SetCellValue("");
break;
}
}
catch
{
cell.SetCellValue(value);
}
}
#endregion
#region 配置校验
......
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