Skip to content

Commit c00f479

Browse files
Fix for issue 876 on the maintenance branch (#879)
* Fixes issue 876 on the maintenance branch * Moved check for sheet name length after the GetSheetInfos call Signed-off-by: Michele Bastione <[email protected]> --------- Signed-off-by: Michele Bastione <[email protected]>
1 parent 9847b6f commit c00f479

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.DefaultOpenXml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ private IEnumerable<Tuple<SheetDto, object>> GetSheets()
2828
{
2929
sheetId++;
3030
var sheetInfos = GetSheetInfos(sheet.Key);
31+
if (sheetInfos.ExcelSheetName.Length > 31)
32+
throw new ArgumentException("Sheet names must be less than 31 characters");
33+
3134
yield return Tuple.Create(sheetInfos.ToDto(sheetId), sheet.Value);
3235
}
3336

@@ -424,3 +427,4 @@ private string GetCellXfId(string styleIndex)
424427
}
425428
}
426429
}
430+

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,4 +4699,24 @@ public void TestIssue869(string fileName, DateOnlyConversionMode mode, bool thro
46994699
}
47004700
}
47014701
}
4702+
4703+
[Fact]
4704+
public void TestIssue876()
4705+
{
4706+
var someTable = new[]
4707+
{
4708+
new { Name = "Jack", Age = 25 },
4709+
};
4710+
4711+
var sheets = new Dictionary<string, object>
4712+
{
4713+
["SomeVeryLongNameWithMoreThan31Characters"] = someTable
4714+
};
4715+
4716+
Assert.Throws<ArgumentException>(() =>
4717+
{
4718+
using var outputPath = AutoDeletingPath.Create();
4719+
MiniExcel.SaveAs(outputPath.ToString(), sheets);
4720+
});
4721+
}
47024722
}

0 commit comments

Comments
 (0)