diff --git a/SpreadCheetah.Test/Tests/SpreadsheetStyledRowTests.cs b/SpreadCheetah.Test/Tests/SpreadsheetStyledRowTests.cs index 233b1b56..82ca5da6 100644 --- a/SpreadCheetah.Test/Tests/SpreadsheetStyledRowTests.cs +++ b/SpreadCheetah.Test/Tests/SpreadsheetStyledRowTests.cs @@ -1043,6 +1043,50 @@ public async Task Spreadsheet_AddRow_ExplicitCellReferencesForStyledCells(CellVa Assert.Equal(expectedRow1Refs, actualSheet2Refs); } + [Theory] + [MemberData(nameof(TestData.StyledCellTypes), MemberType = typeof(TestData))] + public async Task Spreadsheet_AddRow_LongStringValueStyledCells(CellType cellType, RowCollectionType rowType) + { + // Arrange + using var stream = new MemoryStream(); + var options = new SpreadCheetahOptions { BufferSize = SpreadCheetahOptions.MinimumBufferSize }; + await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream, options); + var value = new string('a', options.BufferSize * 2); + var style = new Style(); + style.Fill.Color = Color.Thistle; + var styleId = spreadsheet.AddStyle(style); + + var row1 = Enumerable.Range(1, 10).Select(_ => CellFactory.Create(cellType, value, styleId)).ToList(); + var row2 = Enumerable.Range(1, 1).Select(_ => CellFactory.Create(cellType, value, styleId)).ToList(); + var row3 = Enumerable.Range(1, 100).Select(_ => CellFactory.Create(cellType, value, styleId)).ToList(); + + // Act + await spreadsheet.StartWorksheetAsync("Sheet1"); + await spreadsheet.AddRowAsync(row1, rowType); + await spreadsheet.AddRowAsync(row2, rowType); + await spreadsheet.AddRowAsync(row3, rowType); + + await spreadsheet.StartWorksheetAsync("Sheet2"); + await spreadsheet.AddRowAsync(row1, rowType); + + await spreadsheet.FinishAsync(); + + // Assert + SpreadsheetAssert.Valid(stream); + using var actual = SpreadsheetDocument.Open(stream, true); + var sheetParts = actual.WorkbookPart!.WorksheetParts.ToList(); + Assert.Equal(2, sheetParts.Count); + + var sheet1Rows = sheetParts[0].Worksheet.Descendants().ToList(); + Assert.Equal(3, sheet1Rows.Count); + Assert.All(sheet1Rows[0].Descendants(), x => Assert.Equal(value, x.InnerText)); + Assert.All(sheet1Rows[1].Descendants(), x => Assert.Equal(value, x.InnerText)); + Assert.All(sheet1Rows[2].Descendants(), x => Assert.Equal(value, x.InnerText)); + + var sheet2Row = Assert.Single(sheetParts[1].Worksheet.Descendants()); + Assert.All(sheet2Row.Descendants(), x => Assert.Equal(value, x.InnerText)); + } + [Theory] [MemberData(nameof(TestData.StyledCellTypes), MemberType = typeof(TestData))] public async Task Spreadsheet_AddRow_ExplicitCellReferencesForLongStringValueStyledCells(CellType cellType, RowCollectionType rowType)