Skip to content

Commit

Permalink
Fixes on offset function, now always returning a range
Browse files Browse the repository at this point in the history
  • Loading branch information
swmal committed Dec 27, 2018
1 parent 9b37e2e commit ab64751
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
15 changes: 1 addition & 14 deletions EPPlus/FormulaParsing/Excel/Functions/RefAndLookup/Offset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,7 @@ public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, P
var toCol = (width != 0 ? adr._fromCol + width - 1 : adr._toCol) + colOffset;

var newRange = context.ExcelDataProvider.GetRange(adr.WorkSheet, fromRow, fromCol, toRow, toCol);
if (!newRange.IsMulti)
{
if (newRange.IsEmpty) return CompileResult.Empty;
var val = newRange.GetValue(fromRow, fromCol);
if (IsNumeric(val))
{
return CreateResult(val, DataType.Decimal);
}
if (val is ExcelErrorValue)
{
return CreateResult(val, DataType.ExcelError);
}
return CreateResult(val, DataType.String);
}

return CreateResult(newRange, DataType.Enumerable);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override CompileResult Compile(IEnumerable<Expression> children)
var compileResult = child.Compile();
if (compileResult.IsResultOfSubtotal)
{
var arg = new FunctionArgument(compileResult.Result);
var arg = new FunctionArgument(compileResult.Result, compileResult.DataType);
arg.SetExcelStateFlag(ExcelCellState.IsResultOfSubtotal);
args.Add(arg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void BuildFunctionArguments(CompileResult compileResult, DataType data

protected void BuildFunctionArguments(CompileResult result, List<FunctionArgument> args)
{
BuildFunctionArguments(result, DataType.Unknown, args);
BuildFunctionArguments(result, result.DataType, args);
}

public abstract CompileResult Compile(IEnumerable<Expression> children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ namespace EPPlusTest.FormulaParsing.IntegrationTests.BuiltInFunctions
[TestClass]
public class MathFunctionsTests : FormulaParserTestBase
{
private ExcelPackage _package;

[TestInitialize]
public void Setup()
{
var excelDataProvider = A.Fake<ExcelDataProvider>();
_package = new ExcelPackage();
var excelDataProvider = new EpplusExcelDataProvider(_package);
_parser = new FormulaParser(excelDataProvider);
}

[TestCleanup]
public void Cleanup()
{
_package.Dispose();
}

[TestMethod]
public void PowerShouldReturnCorrectResult()
{
Expand Down Expand Up @@ -391,6 +400,20 @@ public void CountBlankShouldCalculateEmptyCells()
}
}

[TestMethod]
public void CountBlankShouldCalculateResultOfOffset()
{
using (var pck = new ExcelPackage())
{
var sheet = pck.Workbook.Worksheets.Add("test");
sheet.Cells["A1"].Value = 1;
sheet.Cells["B2"].Value = string.Empty;
sheet.Cells["A5"].Formula = "COUNTBLANK(OFFSET(A1, 0, 1))";
sheet.Calculate();
Assert.AreEqual(1, sheet.Cells["A5"].Value);
}
}

[TestMethod]
public void DegreesShouldReturnCorrectResult()
{
Expand Down

0 comments on commit ab64751

Please sign in to comment.