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
5 changes: 3 additions & 2 deletions src/EPPlus/LoadFunctions/LoadFromCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ private void SetValuesAndFormulas(object[,] values, Dictionary<int, FormulaCell>
#endif
if (transpose)
{
values[col++, row] = v;
values[col, row] = v;
}
else
{
values[row, col++] = v;
values[row, col] = v;
}
}
else if (!string.IsNullOrEmpty(colInfo.Formula))
Expand All @@ -226,6 +226,7 @@ private void SetValuesAndFormulas(object[,] values, Dictionary<int, FormulaCell>
{
formulaCells[colInfo.Index] = new FormulaCell { FormulaR1C1 = colInfo.FormulaR1C1 };
}
col++;
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/EPPlusTest/LoadFunctions/LoadFromCollectionAttributesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ internal class Actor2 : Actor

}


internal class Actor3 : Actor
{
[EpplusTableColumn(Order = 10)]
public string Country { get; set; }
}

[EpplusTable(TableStyle = TableStyles.None, PrintHeaders = true, AutofitColumns = true, AutoCalculate = true, ShowLastColumn = true)]
internal class ActorTablestyleNone : Actor
{
Expand All @@ -60,6 +67,13 @@ public class LoadFromCollectionAttributesTests
new Actor{ Salary = 315.34, Tax = 0.28, FirstName = "Lisa", MiddleName = "Maria", LastName = "Gonzales", Birthdate = new DateTime(1971, 10, 2)}
};

private readonly List<Actor3> _actors3 = new List<Actor3>
{
new Actor3{ Salary = 256.24, Tax = 0.21, FirstName = "John", MiddleName = "Bernhard", LastName = "Doe", Birthdate = new DateTime(1950, 3, 15), Country="United Kingdom"},
new Actor3{ Salary = 278.55, Tax = 0.23, FirstName = "Sven", MiddleName = "Bertil", LastName = "Svensson", Birthdate = new DateTime(1962, 6, 10), Country = "Sweden"},
new Actor3{ Salary = 315.34, Tax = 0.28, FirstName = "Lisa", MiddleName = "Maria", LastName = "Gonzales", Birthdate = new DateTime(1971, 10, 2), Country = "Spain"}
};

[TestMethod]
public void ShouldUseAttributeForSorting()
{
Expand Down Expand Up @@ -187,6 +201,23 @@ public void ShouldUseSortOrderAttributeOnClassLevel()
}
}

[TestMethod]
public void I2141_ShouldSortFormulaColumns()
{
using var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("test");
var r = sheet.Cells["A1"].LoadFromCollection(_actors3, true, TableStyles.Dark4);
var table = sheet.Tables[0];
Assert.AreEqual(TableStyles.Dark4, table.TableStyle);
Assert.AreEqual("Birthdate", sheet.Cells["A1"].Value);
Assert.AreEqual("First name", sheet.Cells["B1"].Value);
Assert.AreEqual("Tax", sheet.Cells["F1"].Value);
Assert.AreEqual("John", sheet.Cells["B2"].Value);
Assert.AreEqual("Svensson", sheet.Cells["D3"].Value);
Assert.AreEqual(0.28, sheet.Cells["F4"].Value);
Assert.AreEqual("United Kingdom", sheet.Cells["I2"].Value);
}

[TestMethod]
public void I1395_ShouldHandleDisplayAttributeWithoutOrder()
{
Expand Down