Skip to content

Commit

Permalink
Merge pull request WebApiContrib#39 from WebApiContrib/issue-38
Browse files Browse the repository at this point in the history
Fixes WebApiContrib#38—`headerHeight` constructor parameter now nullable and defaults to `null`.
  • Loading branch information
jordangray committed Mar 19, 2015
2 parents ef0e302 + 7b7043a commit 61aee58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class XlsxMediaTypeFormatter : MediaTypeFormatter
/// <param name="cellHeight">Height of each row of data.</param>
/// <param name="cellStyle">An action method that modifies the worksheet cell style.</param>
/// <param name="headerStyle">An action method that modifies the cell style of the first (header) row in the worksheet.</param>
public XlsxMediaTypeFormatter(bool autoFit = true, bool autoFilter = false, bool freezeHeader = false, double headerHeight = 0, Action<ExcelStyle> cellStyle = null, Action<ExcelStyle> headerStyle = null)
public XlsxMediaTypeFormatter(bool autoFit = true, bool autoFilter = false, bool freezeHeader = false, double? headerHeight = null, Action<ExcelStyle> cellStyle = null, Action<ExcelStyle> headerStyle = null)
{
SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ public void WriteToStreamAsync_WithArrayOfDateTime_WritesExcelDocumentToStream()
Assert.AreEqual(data[1], sheet.GetValue<DateTime>(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()
{
Expand Down

0 comments on commit 61aee58

Please sign in to comment.