Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/EPPlus/FormulaParsing/Excel/Functions/Logical/Ifs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public override CompileResult Execute(IList<FunctionArgument> arguments, Parsing
}
public override bool ReturnsReference => true;
public override bool IsVolatile => true;
public override ExcelFunctionArrayBehaviour ArrayBehaviour => ExcelFunctionArrayBehaviour.Custom;
public override void ConfigureArrayBehaviour(ArrayBehaviourConfig config)
{
var ixArray = new int[127];
for (var ix = 0; ix < 254; ix += 2)
{
ixArray[ix / 2] = ix;
}
config.SetArrayParameterIndexes(ixArray);
}
public override ExcelFunctionParametersInfo ParametersInfo => new ExcelFunctionParametersInfo(new Func<int, FunctionParameterInformation>((argumentIndex) =>
{
if (argumentIndex % 2 == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public override CompileResult Execute(IList<FunctionArgument> arguments, Parsing
}
sortOrders.Add((short)sortOrder);
}
sortOrders.Add((short)1); //row order as last sort criteria to ensure same order as Excel.
var sortByImpl = new SortByImpl(range, byRanges, sortOrders, direction);
var sortedRange = sortByImpl.Sort();
return CreateDynamicArrayResult(sortedRange, DataType.ExcelRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Date Author Change
*************************************************************************************************
22/3/2023 EPPlus Software AB EPPlus v7
*************************************************************************************************/
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateAndTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup.LookupUtils;
using OfficeOpenXml.FormulaParsing.Ranges;
using System;
Expand Down Expand Up @@ -100,6 +101,7 @@ private List<SortInfo> GetSortedRows()
{
cols.CompareData.Add(_byRanges[byRange].GetOffset(row, 0));
}
cols.CompareData.Add(row); //Sort by original row order as last criteria to ensure same order as Excel.
rows.Add(cols);
}
rows.Sort((a, b) =>
Expand Down Expand Up @@ -136,6 +138,7 @@ private List<SortInfo> GetSortedCols()
{
rows.CompareData.Add(_byRanges[byRange].GetOffset(0, col));
}
rows.CompareData.Add(col); //Sort by original row order as last criteria to ensure same order as Excel.
cols.Add(rows);
}
cols.Sort((a, b) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EPPlusTest.FormulaParsing.Excel.Functions.RefAndLookup
{
Expand Down Expand Up @@ -131,7 +127,7 @@ public void SortByColAscending_NullValues_1()
Assert.AreEqual("Street 1", _sheet.Cells["B4"].Value);
Assert.AreEqual("Phil", _sheet.Cells["A5"].Value);
Assert.AreEqual("Steve", _sheet.Cells["A6"].Value);

}

[TestMethod]
Expand All @@ -153,9 +149,33 @@ public void SortByColAscending_NullValues_2()
_sheet.Calculate();
Assert.AreEqual("Phil", _sheet.Cells["A4"].Value);
Assert.AreEqual("Street 3", _sheet.Cells["B4"].Value);
Assert.AreEqual("Steve", _sheet.Cells["A5"].Value);
Assert.AreEqual("Bob", _sheet.Cells["A6"].Value);
Assert.AreEqual("Bob", _sheet.Cells["A5"].Value);
Assert.AreEqual("Steve", _sheet.Cells["A6"].Value);
}
[TestMethod]
public void SortByColShould()
{
_sheet.Cells["A1"].Value = "Bob";
_sheet.Cells["B1"].Value = "Street 2";
_sheet.Cells["A2"].Value = "Bob";
_sheet.Cells["B2"].Value = "Street 1";
_sheet.Cells["A3"].Value = "Steve";
_sheet.Cells["B3"].Value = "Street 3";
_sheet.Cells["A4"].Value = "Bob";
_sheet.Cells["B4"].Value = "Street 3";
_sheet.Cells["A5"].Value = "Steve";
_sheet.Cells["B5"].Value = "Street 4";
_sheet.Cells["A6"].Value = "Bob";
_sheet.Cells["B6"].Value = "Street 0";

_sheet.Cells["A7"].Formula = "SORTBY(A1:B6,A1:A6)";
_sheet.Calculate();
Assert.AreEqual("Street 2", _sheet.Cells["B7"].Value);
Assert.AreEqual("Street 1", _sheet.Cells["B8"].Value);
Assert.AreEqual("Street 3", _sheet.Cells["B9"].Value);
Assert.AreEqual("Street 0", _sheet.Cells["B10"].Value);
Assert.AreEqual("Street 3", _sheet.Cells["B11"].Value);
Assert.AreEqual("Street 4", _sheet.Cells["B12"].Value);
}
}
}
15 changes: 15 additions & 0 deletions src/EPPlusTest/Issues/FormulaCalculationIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,21 @@ public void s1023NegNumericString()
Assert.AreEqual(-11150d, s.Cells["A1"].Value);
}
}
[TestMethod]
public void s1029()
{
using var p = OpenTemplatePackage("AR Aging Analysis.xlsx");
var wb = p.Workbook;
var ws = wb.Worksheets["Filtered data"];
wb.FullCalcOnLoad = false;
wb.CalcMode = ExcelCalcMode.Manual;
ws.Cells["Q2"].Calculate();
Assert.AreEqual("365" ,ws.Cells["Q2"].Value);
Assert.AreEqual("181-365", ws.Cells["Q45"].Value);
Assert.AreEqual("90", ws.Cells["Q55"].Value);
Assert.AreEqual(6D, ws.Cells["A34"].Value);
SaveAndCleanup(p);
}
}
}