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
1 change: 1 addition & 0 deletions src/MiniExcel.OpenXml/Models/MergeCells.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace MiniExcelLib.OpenXml.Models;
internal class MergeCells
{
public Dictionary<string, object?> MergesValues { get; set; } = [];
public Dictionary<string, string?> MergesStyles { get; set; } = [];
public Dictionary<string, string> MergesMap { get; set; } = [];
}
2 changes: 2 additions & 0 deletions src/MiniExcel.OpenXml/Reader/OpenXmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,12 @@ internal static async Task<OpenXmlReader> CreateAsync(Stream stream, IMiniExcelC
if (mergeCells?.MergesValues.ContainsKey(aR) ?? false)
{
mergeCells.MergesValues[aR] = cellValue;
mergeCells.MergesStyles[aR] = aS;
}
else if (mergeCells?.MergesMap.TryGetValue(aR, out var mergeKey) ?? false)
{
mergeCells.MergesValues.TryGetValue(mergeKey, out cellValue);
mergeCells.MergesStyles.TryGetValue(mergeKey, out aS);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/MiniExcel.OpenXml.Tests/Issues/MiniExcelGithubIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3345,4 +3345,39 @@ public void QueryReturnsTextCellsWithDateOrTimeFormatAsString()
Assert.Equal(TimeSpan.FromHours(12), (object)row.E);
Assert.Equal("0.5", (object)row.F);
}

// https://github.com/mini-software/MiniExcel/issues/550
[Fact]
public void FillMergedCellsAppliesTheStyleOfTheFirstCellOfTheMergedRange()
{
using var path = AutoDeletingPath.Create();
_excelExporter.Export(path.FilePath, new[] { new { Value = "control" } });
SheetHelper.ReplaceStylesXml(path.FilePath, """
<?xml version="1.0" encoding="utf-8"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<cellXfs count="2">
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" />
<xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" />
</cellXfs>
</styleSheet>
""");
SheetHelper.ReplaceFirstSheetXml(path.FilePath, """
<?xml version="1.0" encoding="utf-8"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<dimension ref="A1:A3" />
<sheetData>
<row r="1"><c r="A1" s="1"><v>46327</v></c></row>
<row r="2"><c r="A2" /></row>
<row r="3"><c r="A3" s="0" /></row>
</sheetData>
<mergeCells count="1"><mergeCell ref="A1:A3" /></mergeCells>
</worksheet>
""");

var config = new OpenXmlConfiguration { FillMergedCells = true };
var rows = _excelImporter.Query(path.FilePath, configuration: config).ToList();

Assert.Equal(3, rows.Count);
Assert.All(rows, row => Assert.Equal(new DateTime(2026, 11, 1), (object)row.A));
}
}
Loading