Migrate ExcelIO from ClosedXML to NPOI

This commit is contained in:
Joseph Doherty
2026-02-06 17:27:09 -05:00
parent 070d915b12
commit dd18a05408
26 changed files with 3034 additions and 2805 deletions
@@ -1,75 +1,77 @@
using ClosedXML.Excel;
using JdeScoping.ExcelIO.Tests.Fixtures;
using Shouldly;
using Xunit;
namespace JdeScoping.ExcelIO.Tests.Integration;
public class ProtectionAndStyleTests : IClassFixture<WithMisDataFixture>
{
private readonly XLWorkbook _workbook;
public ProtectionAndStyleTests(WithMisDataFixture fixture)
{
_workbook = fixture.Workbook;
}
[Fact]
public void AllDataSheets_AreProtected()
{
_workbook.Worksheet("Search Results").Protection.IsProtected.ShouldBeTrue();
_workbook.Worksheet("MIS Info").Protection.IsProtected.ShouldBeTrue();
_workbook.Worksheet("Investigation").Protection.IsProtected.ShouldBeTrue();
}
[Fact]
public void Protection_AllowsFiltering()
{
var sheet = _workbook.Worksheet("Search Results");
sheet.Protection.AllowedElements.HasFlag(XLSheetProtectionElements.AutoFilter).ShouldBeTrue();
}
[Fact]
public void Protection_AllowsSorting()
{
var sheet = _workbook.Worksheet("Search Results");
sheet.Protection.AllowedElements.HasFlag(XLSheetProtectionElements.Sort).ShouldBeTrue();
}
[Fact]
public void Protection_AllowsFormatting()
{
var sheet = _workbook.Worksheet("Search Results");
sheet.Protection.AllowedElements.HasFlag(XLSheetProtectionElements.FormatCells).ShouldBeTrue();
sheet.Protection.AllowedElements.HasFlag(XLSheetProtectionElements.FormatColumns).ShouldBeTrue();
sheet.Protection.AllowedElements.HasFlag(XLSheetProtectionElements.FormatRows).ShouldBeTrue();
}
[Fact]
public void AllTables_UseLight18Style()
{
_workbook.Worksheet("Search Results").Tables.First().Theme.ShouldBe(XLTableTheme.TableStyleLight18);
_workbook.Worksheet("MIS Info").Tables.First().Theme.ShouldBe(XLTableTheme.TableStyleLight18);
_workbook.Worksheet("Investigation").Tables.First().Theme.ShouldBe(XLTableTheme.TableStyleLight18);
}
[Fact]
public void HeaderCells_HaveCorrectFormatting()
{
var sheet = _workbook.Worksheet("Search Criteria");
var headerCell = sheet.Cell(1, 1);
headerCell.Style.Font.Bold.ShouldBeTrue();
headerCell.Style.Fill.BackgroundColor.ShouldBe(XLColor.Gainsboro);
headerCell.Style.Alignment.Horizontal.ShouldBe(XLAlignmentHorizontalValues.Center);
}
[Fact]
public void CriteriaTimestamp_MatchesLegacyFormat()
{
var sheet = _workbook.Worksheet("Search Criteria");
var timestamp = sheet.Cell(4, 2).Value.GetText();
timestamp.ShouldContain("Jan 15, 2024");
timestamp.ShouldContain("02:30:45");
timestamp.ShouldContain("EST");
}
}
using JdeScoping.ExcelIO.Tests.Fixtures;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Shouldly;
using Xunit;
namespace JdeScoping.ExcelIO.Tests.Integration;
public class ProtectionAndStyleTests : IClassFixture<WithMisDataFixture>
{
private readonly XSSFWorkbook _workbook;
public ProtectionAndStyleTests(WithMisDataFixture fixture)
{
_workbook = fixture.Workbook;
}
[Fact]
public void AllDataSheets_AreProtected()
{
((XSSFSheet)_workbook.GetSheet("Search Results")!).IsSheetLocked.ShouldBeTrue();
((XSSFSheet)_workbook.GetSheet("MIS Info")!).IsSheetLocked.ShouldBeTrue();
((XSSFSheet)_workbook.GetSheet("Investigation")!).IsSheetLocked.ShouldBeTrue();
}
[Fact]
public void Protection_AllowsFiltering()
{
var sheet = (XSSFSheet)_workbook.GetSheet("Search Results")!;
sheet.IsAutoFilterLocked.ShouldBeFalse();
}
[Fact]
public void Protection_AllowsSorting()
{
var sheet = (XSSFSheet)_workbook.GetSheet("Search Results")!;
sheet.IsSortLocked.ShouldBeFalse();
}
[Fact]
public void Protection_AllowsFormatting()
{
var sheet = (XSSFSheet)_workbook.GetSheet("Search Results")!;
sheet.IsFormatCellsLocked.ShouldBeFalse();
sheet.IsFormatColumnsLocked.ShouldBeFalse();
sheet.IsFormatRowsLocked.ShouldBeFalse();
}
[Fact]
public void AllTables_UseLight18Style()
{
ExcelTestHelpers.GetFirstTable(_workbook.GetSheet("Search Results")!).StyleName.ShouldBe("TableStyleLight18");
ExcelTestHelpers.GetFirstTable(_workbook.GetSheet("MIS Info")!).StyleName.ShouldBe("TableStyleLight18");
ExcelTestHelpers.GetFirstTable(_workbook.GetSheet("Investigation")!).StyleName.ShouldBe("TableStyleLight18");
}
[Fact]
public void HeaderCells_HaveCorrectFormatting()
{
var sheet = _workbook.GetSheet("Search Criteria")!;
var headerCell = ExcelTestHelpers.GetCell(sheet, 1, 1)!;
(headerCell.CellStyle.FontIndex >= 0 &&
_workbook.GetFontAt(headerCell.CellStyle.FontIndex).IsBold).ShouldBeTrue();
ExcelTestHelpers.GetFillForegroundRgb(headerCell).ShouldBe([0xDC, 0xDC, 0xDC]);
headerCell.CellStyle.Alignment.ShouldBe(HorizontalAlignment.Center);
}
[Fact]
public void CriteriaTimestamp_MatchesLegacyFormat()
{
var sheet = _workbook.GetSheet("Search Criteria")!;
var timestamp = ExcelTestHelpers.GetCellText(sheet, 4, 2);
timestamp.ShouldContain("Jan 15, 2024");
timestamp.ShouldContain("02:30:45");
timestamp.ShouldContain("EST");
}
}