Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HeaderHeight is a nullable double on XlsxMediaTypeFormatter, but the
constructor only accepts a non-nullable double. By changing this to nullable
the consumer can now ignore the height and it will use the default. The lack
of this feature only seemed to affect MS Excel. Previously the height was set
to zero, and "hidding" it in MS Excel. Google Spreadsheets seemed unaffected.
  • Loading branch information
ChrisMissal committed Mar 6, 2015
1 parent ef0e302 commit 7b7043a
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 7b7043a

Please sign in to comment.