Skip to content

Commit

Permalink
Update ExcelDataFlowSource.cs
Browse files Browse the repository at this point in the history
Syntax tidy
  • Loading branch information
jas88 committed Oct 10, 2023
1 parent add79de commit 8114140
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Rdmp.Core/DataLoad/Modules/DataFlowSources/ExcelDataFlowSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Rdmp.Core.DataFlowPipeline;
using Rdmp.Core.DataFlowPipeline.Requirements;
using Rdmp.Core.DataLoad.Modules.Exceptions;
using Rdmp.Core.ReusableLibraryCode.Annotations;
using Rdmp.Core.ReusableLibraryCode.Checks;
using Rdmp.Core.ReusableLibraryCode.Progress;

Expand Down Expand Up @@ -198,7 +199,7 @@ public DataTable GetAllData(ISheet worksheet, IDataLoadEventListener listener)
/// <param name="cell">The cell whose value you want to retrieve</param>
/// <param name="treatAs">Leave blank, used in recursion for dealing with Formula cells</param>
/// <returns></returns>
private object GetCellValue(ICell cell, CellType treatAs = CellType.Unknown)
private object GetCellValue([CanBeNull] ICell cell, CellType treatAs = CellType.Unknown)
{
if (cell == null)
return null;
Expand All @@ -218,8 +219,8 @@ private object GetCellValue(ICell cell, CellType treatAs = CellType.Unknown)

//some numerics are actually dates/times
if (cell.CellStyle.DataFormat == 0) return cell.NumericCellValue;

var format = cell.CellStyle.GetDataFormatString();
var f = new NumberFormat(format);

if (IsDateWithoutTime(format))
return cell.DateCellValue.ToString("yyyy-MM-dd");
Expand All @@ -230,19 +231,17 @@ private object GetCellValue(ICell cell, CellType treatAs = CellType.Unknown)
if (IsTimeWithoutDate(format))
return cell.DateCellValue.ToString("HH:mm:ss");

return IsDateFormat(format)
? f.Format(cell.DateCellValue, CultureInfo.InvariantCulture)
: f.Format(cell.NumericCellValue, CultureInfo.InvariantCulture);
return new NumberFormat(format).Format(
IsDateFormat(format) ? cell.DateCellValue : cell.NumericCellValue, CultureInfo.InvariantCulture);

case CellType.String:

var v = cell.StringCellValue;

//if it is blank or 'null' then leave it null
if (string.IsNullOrWhiteSpace(v) || v.Trim().Equals("NULL", StringComparison.CurrentCultureIgnoreCase))
return null;
return string.IsNullOrWhiteSpace(cell.StringCellValue) ||
cell.StringCellValue.Trim().Equals("NULL", StringComparison.CurrentCultureIgnoreCase)
? null
: cell.StringCellValue;

return cell.StringCellValue;
case CellType.Formula:
return GetCellValue(cell, cell.CachedFormulaResultType);
case CellType.Blank:
Expand All @@ -252,7 +251,7 @@ private object GetCellValue(ICell cell, CellType treatAs = CellType.Unknown)
case CellType.Error:
return null;
default:
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(treatAs));
}
}

Expand Down

0 comments on commit 8114140

Please sign in to comment.