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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ private IEnumerable<Tuple<SheetDto, object>> GetSheets()
{
sheetId++;
var sheetInfos = GetSheetInfos(sheet.Key);
if (sheetInfos.ExcelSheetName.Length > 31)
throw new ArgumentException("Sheet names must be less than 31 characters");

yield return Tuple.Create(sheetInfos.ToDto(sheetId), sheet.Value);
}

Expand Down Expand Up @@ -424,3 +427,4 @@ private string GetCellXfId(string styleIndex)
}
}
}

20 changes: 20 additions & 0 deletions tests/MiniExcelTests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4699,4 +4699,24 @@ public void TestIssue869(string fileName, DateOnlyConversionMode mode, bool thro
}
}
}

[Fact]
public void TestIssue876()
{
var someTable = new[]
{
new { Name = "Jack", Age = 25 },
};

var sheets = new Dictionary<string, object>
{
["SomeVeryLongNameWithMoreThan31Characters"] = someTable
};

Assert.Throws<ArgumentException>(() =>
{
using var outputPath = AutoDeletingPath.Create();
MiniExcel.SaveAs(outputPath.ToString(), sheets);
});
}
Comment on lines +4704 to +4721
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a good test for the IDictionary<string, object> case. To ensure complete coverage for the fix, it would be beneficial to add similar tests for DataSet and for the default sheet name scenario. This will help verify that the sheet name length validation is applied consistently across all ways of creating sheets.

}
Loading