Skip to content

Commit 934a560

Browse files
committed
Fixes issue #1982 and #2002
1 parent c9307b8 commit 934a560

5 files changed

Lines changed: 41 additions & 18 deletions

File tree

src/EPPlus/FormulaParsing/Excel/Functions/MathFunctions/RangeCriteriaFunction.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,21 @@ protected static Queue<FormulaRangeAddress> EnqueueMatchingAddresses(FormulaRang
179179
var pIx = int.MinValue;
180180
var extRef = valueAddress.ExternalReferenceIx;
181181
var wsIx = valueAddress.WorksheetIx;
182+
FormulaRangeAddress currentAddress=null;
182183
if (valueAddress.FromCol == valueAddress.ToCol)
183184
{
184185
var c = valueAddress.FromCol;
185186
foreach (var ix in matchIndexes)
186187
{
187188
if (ix == pIx + 1)
188189
{
189-
addresses.Peek().ToRow++;
190+
currentAddress.ToRow++;
190191
}
191192
else
192193
{
193194
var r = valueAddress.FromRow + ix;
194-
addresses.Enqueue(new FormulaRangeAddress() { ExternalReferenceIx=extRef, WorksheetIx = wsIx, FromRow = r, ToRow = r, FromCol = c, ToCol = c });
195+
currentAddress = new FormulaRangeAddress() { ExternalReferenceIx = extRef, WorksheetIx = wsIx, FromRow = r, ToRow = r, FromCol = c, ToCol = c };
196+
addresses.Enqueue(currentAddress);
195197
}
196198
pIx = ix;
197199
}
@@ -203,12 +205,13 @@ protected static Queue<FormulaRangeAddress> EnqueueMatchingAddresses(FormulaRang
203205
{
204206
if (ix == pIx + 1)
205207
{
206-
addresses.Peek().ToCol++;
208+
currentAddress.ToCol++;
207209
}
208210
else
209211
{
210212
var c = valueAddress.FromCol + ix;
211-
addresses.Enqueue(new FormulaRangeAddress() { ExternalReferenceIx = extRef, WorksheetIx = wsIx, FromRow = r, ToRow = r, FromCol = c, ToCol = c });
213+
currentAddress = new FormulaRangeAddress() { ExternalReferenceIx = extRef, WorksheetIx = wsIx, FromRow = r, ToRow = r, FromCol = c, ToCol = c };
214+
addresses.Enqueue(currentAddress);
212215
}
213216
pIx = ix;
214217
}

src/EPPlus/LoadFunctions/LoadFunctionBase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ internal ExcelRangeBase Load()
8787
{
8888
var nRows = PrintHeaders ? GetNumberOfRows() + 1 : GetNumberOfRows();
8989
var nCols = GetNumberOfColumns();
90-
var values = new object[transpose ? nCols : nRows, transpose ? nRows : nCols];
91-
92-
//if(Range.Worksheet._values.Capacity < values.Length)
93-
//{
94-
// Range.Worksheet._values.Capacity = values.Length;
95-
//}
90+
if (transpose)
91+
{
92+
var t = nRows;
93+
nRows = nCols;
94+
nCols = t;
95+
}
96+
var values = new object[nRows, nCols];
9697

9798
LoadInternal(values, out Dictionary<int, FormulaCell> formulaCells, out Dictionary<int, string> columnFormats);
9899
var ws = Range.Worksheet;
@@ -122,7 +123,7 @@ internal ExcelRangeBase Load()
122123
return null;
123124
}
124125

125-
var r = transpose ? ws.Cells[Range._fromRow, Range._fromCol, Range._fromRow + nCols - 1, Range._fromCol + nRows - 1] : ws.Cells[Range._fromRow, Range._fromCol, Range._fromRow + nRows - 1, Range._fromCol + nCols - 1];
126+
var r = ws.Cells[Range._fromRow, Range._fromCol, Range._fromRow + nRows - 1, Range._fromCol + nCols - 1];
126127

127128
if (TableStyle.HasValue)
128129
{

src/EPPlusTest/Issues/FormulaCalculationIssues.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,22 @@ public void s853()
942942
Assert.AreEqual(12273.13, sheet.Cells["AI61"].Value);
943943
Assert.AreEqual(-472.69, sheet.Cells["AI70"].Value);
944944
}
945+
[TestMethod]
946+
public void s858()
947+
{
948+
using var p1 = OpenTemplatePackage("s858-1.xlsx");
949+
var ws1 = p1.Workbook.Worksheets["Aico Data"];
950+
ws1.Calculate();
951+
var result1 = ws1.Cells["D55"].Value;
952+
Assert.AreEqual(265509.38, result1);
953+
954+
using var p2 = OpenTemplatePackage("s858-2.xlsx");
955+
var ws2 = p2.Workbook.Worksheets["Aico data"];
956+
ws2.Calculate();
957+
var result2 = ws2.Cells["E55"].Value;
958+
959+
Assert.AreEqual(12977661.57, result2);
960+
}
945961
}
946962
}
947963

src/EPPlusTest/Issues/PackageIssues.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public void i1808()
117117
SaveAndCleanup(package);
118118
}
119119
}
120-
120+
[TestMethod]
121+
public void i1231()
122+
{
123+
using (ExcelPackage package = OpenTemplatePackage("i1231.xlsx"))
124+
{
125+
var ws = package.Workbook.Worksheets[0];
126+
SaveAndCleanup(package);
127+
}
128+
}
121129
}
122130
}

src/EPPlusTest/Issues/PictureIssues.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using OfficeOpenXml.Drawing;
3-
using OfficeOpenXml.Drawing.Chart;
4-
using System.Drawing;
5-
using System.IO;
6-
using System.Runtime.InteropServices;
7-
using System.Xml.Linq;
83
namespace EPPlusTest.Issues
94
{
10-
[TestClass]
5+
[TestClass]
116
public class PictureIssues : TestBase
127

138
{

0 commit comments

Comments
 (0)