diff --git a/src/WebApiContrib.Formatting.Xlsx/XlsxMediaTypeFormatter.cs b/src/WebApiContrib.Formatting.Xlsx/XlsxMediaTypeFormatter.cs index f49e43d..3adbbc1 100644 --- a/src/WebApiContrib.Formatting.Xlsx/XlsxMediaTypeFormatter.cs +++ b/src/WebApiContrib.Formatting.Xlsx/XlsxMediaTypeFormatter.cs @@ -66,7 +66,7 @@ public class XlsxMediaTypeFormatter : MediaTypeFormatter /// Height of each row of data. /// An action method that modifies the worksheet cell style. /// An action method that modifies the cell style of the first (header) row in the worksheet. - public XlsxMediaTypeFormatter(bool autoFit = true, bool autoFilter = false, bool freezeHeader = false, double headerHeight = 0, Action cellStyle = null, Action headerStyle = null) + public XlsxMediaTypeFormatter(bool autoFit = true, bool autoFilter = false, bool freezeHeader = false, double? headerHeight = null, Action cellStyle = null, Action headerStyle = null) { SupportedMediaTypes.Clear(); SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")); diff --git a/test/WebApiContrib.Formatting.Xlsx.Tests/XlsxMediaTypeFormatterTests.cs b/test/WebApiContrib.Formatting.Xlsx.Tests/XlsxMediaTypeFormatterTests.cs index 2718b24..bdd81d9 100644 --- a/test/WebApiContrib.Formatting.Xlsx.Tests/XlsxMediaTypeFormatterTests.cs +++ b/test/WebApiContrib.Formatting.Xlsx.Tests/XlsxMediaTypeFormatterTests.cs @@ -397,6 +397,20 @@ public void WriteToStreamAsync_WithArrayOfDateTime_WritesExcelDocumentToStream() Assert.AreEqual(data[1], sheet.GetValue(2, 1), "Value in A2 is incorrect."); } + [TestMethod] + public void XlsxMediaTypeFormatter_WithDefaultHeaderHeight_DefaultsToSameHeightForAllCells() + { + var data = new[] { new SimpleTestItem { Value1 = "A1", Value2 = "B1" }, + new SimpleTestItem { Value1 = "A1", Value2 = "B2" } }; + + var formatter = new XlsxMediaTypeFormatter(); + + var sheet = GetWorksheetFromStream(formatter, data); + + Assert.AreNotEqual(sheet.Row(1).Height, 0d, "HeaderHeight should not be zero"); + Assert.AreEqual(sheet.Row(1).Height, sheet.Row(2).Height, "HeaderHeight should be the same as other rows"); + } + [TestMethod] public void WriteToStreamAsync_WithCellAndHeaderFormats_WritesFormattedExcelDocumentToStream() {