From 76a1126e9a45eac1e93f47596936c3e171d14625 Mon Sep 17 00:00:00 2001 From: Dan Friedman Date: Wed, 30 May 2018 21:24:27 -0500 Subject: [PATCH 1/3] Replace Tabular with EPPlus and CsvHelper --- src/extensions/Wyam.Tables/CsvFile.cs | 62 +++++++++++++++++++ src/extensions/Wyam.Tables/CsvToHtml.cs | 13 ++-- src/extensions/Wyam.Tables/CsvToMarkdown.cs | 25 ++++---- src/extensions/Wyam.Tables/ExcelFile.cs | 53 ++++++++++++++++ src/extensions/Wyam.Tables/ExcelToCsv.cs | 15 ++--- src/extensions/Wyam.Tables/Wyam.Tables.csproj | 6 +- .../Wyam.Tables.Tests/CsvToHtmlFixture.cs | 4 +- .../Wyam.Tables.Tests.csproj | 2 +- 8 files changed, 141 insertions(+), 39 deletions(-) create mode 100644 src/extensions/Wyam.Tables/CsvFile.cs create mode 100644 src/extensions/Wyam.Tables/ExcelFile.cs diff --git a/src/extensions/Wyam.Tables/CsvFile.cs b/src/extensions/Wyam.Tables/CsvFile.cs new file mode 100644 index 000000000..263273329 --- /dev/null +++ b/src/extensions/Wyam.Tables/CsvFile.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.IO; +using CsvHelper; +using CsvHelper.Configuration; + +namespace Wyam.Tables +{ + internal static class CsvFile + { + public static IEnumerable> GetAllRecords(Stream stream, string delimiter = null) + { + using (var reader = new StreamReader(stream)) + { + return GetAllRecords(reader, delimiter); + } + } + + public static IEnumerable> GetAllRecords(TextReader reader, string delimiter = null) + { + List> records = new List>(); + var configuration = delimiter == null ? new Configuration { HasHeaderRecord = false } : new Configuration { HasHeaderRecord = false, Delimiter = delimiter }; + + using (var csv = new CsvReader(reader, configuration)) + { + while (csv.Read()) + { + var currentRecord = csv.Context.Record; + records.Add(currentRecord); + } + } + + return records; + } + + public static void WriteAllRecords(IEnumerable> records, Stream stream) + { + var writer = new StreamWriter(stream); + WriteAllRecords(records, writer); + writer.Flush(); + } + + public static void WriteAllRecords(IEnumerable> records, TextWriter writer) + { + if (records == null) + { + return; + } + + var csv = new CsvWriter(writer, new Configuration { QuoteAllFields = true }); + { + foreach (var row in records) + { + foreach (var cell in row) + { + csv.WriteField(cell ?? string.Empty); + } + csv.NextRecord(); + } + } + } + } +} diff --git a/src/extensions/Wyam.Tables/CsvToHtml.cs b/src/extensions/Wyam.Tables/CsvToHtml.cs index df919351b..9175e5db5 100644 --- a/src/extensions/Wyam.Tables/CsvToHtml.cs +++ b/src/extensions/Wyam.Tables/CsvToHtml.cs @@ -2,12 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using Wyam.Common.Documents; -using Wyam.Common.Modules; using Wyam.Common.Execution; +using Wyam.Common.Modules; using Wyam.Common.Tracing; -using Wyam.Common.Util; namespace Wyam.Tables { @@ -41,24 +39,23 @@ public IEnumerable Execute(IReadOnlyList inputs, IExecutio { try { - Tabular.Csv csv = new Tabular.Csv() { Data = input.Content }; - Tabular.Table table = Tabular.Csv.FromCsv(csv); + var records = CsvFile.GetAllRecords(input.GetStream()); StringBuilder builder = new StringBuilder(); bool firstLine = true; builder.AppendLine(""); - foreach (var row in table.Rows) + foreach (var row in records) { builder.AppendLine(""); foreach (var cell in row) { if (_firstLineHeader && firstLine) { - builder.AppendLine($""); + builder.AppendLine($""); } else { - builder.AppendLine($""); + builder.AppendLine($""); } } builder.AppendLine(""); diff --git a/src/extensions/Wyam.Tables/CsvToMarkdown.cs b/src/extensions/Wyam.Tables/CsvToMarkdown.cs index 6489b9268..9bab4cd6d 100644 --- a/src/extensions/Wyam.Tables/CsvToMarkdown.cs +++ b/src/extensions/Wyam.Tables/CsvToMarkdown.cs @@ -2,12 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using Wyam.Common.Documents; -using Wyam.Common.Modules; using Wyam.Common.Execution; +using Wyam.Common.Modules; using Wyam.Common.Tracing; -using Wyam.Common.Util; namespace Wyam.Tables { @@ -47,37 +45,36 @@ public IEnumerable Execute(IReadOnlyList inputs, IExecutio { try { - Tabular.Csv csv = new Tabular.Csv() { Data = input.Content }; - Tabular.Table table = Tabular.Csv.FromCsv(csv); + var records = CsvFile.GetAllRecords(input.GetStream()); StringBuilder builder = new StringBuilder(); - int columnCount = table.First().Count; + int columnCount = records.First().Count(); int[] columnSize = new int[columnCount]; - foreach (var row in table.Rows) + foreach (var row in records) { - for (int i = 0; i < row.Count; i++) + for (int i = 0; i < row.Count(); i++) { - var cell = row[i]; - columnSize[i] = Math.Max(columnSize[i], cell.Value.Length); + var cell = row.ElementAt(i); + columnSize[i] = Math.Max(columnSize[i], cell.Length); } } bool firstLine = true; WriteLine(builder, columnSize); - foreach (var row in table.Rows) + foreach (var row in records) { builder.Append("|"); for (int i = 0; i < columnSize.Length; i++) { builder.Append(" "); - builder.Append(row[i].Value); - builder.Append(' ', columnSize[i] - row[i].Value.Length + 1); + builder.Append(row.ElementAt(i)); + builder.Append(' ', columnSize[i] - row.ElementAt(i).Length + 1); builder.Append("|"); } builder.AppendLine(); - WriteLine(builder, columnSize, this._firstLineHeader && firstLine); + WriteLine(builder, columnSize, _firstLineHeader && firstLine); firstLine = false; } diff --git a/src/extensions/Wyam.Tables/ExcelFile.cs b/src/extensions/Wyam.Tables/ExcelFile.cs new file mode 100644 index 000000000..95f1926e6 --- /dev/null +++ b/src/extensions/Wyam.Tables/ExcelFile.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using OfficeOpenXml; + +namespace Wyam.Tables +{ + internal static class ExcelFile + { + public static IEnumerable> GetAllRecords(Stream stream, int sheetNumber = 1) + { + using (var excel = new ExcelPackage(stream)) + { + if (sheetNumber > excel.Workbook.Worksheets.Count) + { + return null; + } + + var sheet = excel.Workbook.Worksheets[sheetNumber]; + + return GetAllRecords(sheet); + } + } + + public static IEnumerable> GetAllRecords(ExcelWorksheet sheet) + { + var dimension = sheet.Dimension; + + if (dimension == null) + { + return null; + } + + var rowList = new List>(); + int rowCount = dimension.Rows; + int columnCount = dimension.Columns; + + for (var r = 1; r <= rowCount; r++) + { + var rowValues = new List(columnCount); + for (var c = 1; c <= columnCount; c++) + { + var cell = sheet.Cells[r, c].FirstOrDefault(); + rowValues.Add(cell?.Value?.ToString()); + } + + rowList.Add(rowValues); + } + + return rowList; + } + } +} diff --git a/src/extensions/Wyam.Tables/ExcelToCsv.cs b/src/extensions/Wyam.Tables/ExcelToCsv.cs index a63f1abd9..4f29f74f4 100644 --- a/src/extensions/Wyam.Tables/ExcelToCsv.cs +++ b/src/extensions/Wyam.Tables/ExcelToCsv.cs @@ -2,14 +2,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Wyam.Common.Configuration; using Wyam.Common.Documents; -using Wyam.Common.Modules; using Wyam.Common.Execution; +using Wyam.Common.Modules; using Wyam.Common.Tracing; -using Wyam.Common.Util; namespace Wyam.Tables { @@ -30,13 +26,12 @@ public IEnumerable Execute(IReadOnlyList inputs, IExecutio { try { - Tabular.Table table; - using (Stream stream = input.GetStream()) + var records = ExcelFile.GetAllRecords(input.GetStream()); + using (var stream = new MemoryStream()) { - table = Tabular.Excel.ReadFrom(stream, Tabular.ExcelFormat.Excel2007); + CsvFile.WriteAllRecords(records, stream); + return context.GetDocument(input, stream); } - Tabular.Csv csv = Tabular.Csv.ToCsv(table); - return context.GetDocument(input, context.GetContentStream(csv.Data)); } catch (Exception e) { diff --git a/src/extensions/Wyam.Tables/Wyam.Tables.csproj b/src/extensions/Wyam.Tables/Wyam.Tables.csproj index 01f83b0c0..cc9ef1253 100644 --- a/src/extensions/Wyam.Tables/Wyam.Tables.csproj +++ b/src/extensions/Wyam.Tables/Wyam.Tables.csproj @@ -10,9 +10,7 @@ - - - - + + \ No newline at end of file diff --git a/tests/extensions/Wyam.Tables.Tests/CsvToHtmlFixture.cs b/tests/extensions/Wyam.Tables.Tests/CsvToHtmlFixture.cs index b5471ac91..ea0c21033 100644 --- a/tests/extensions/Wyam.Tables.Tests/CsvToHtmlFixture.cs +++ b/tests/extensions/Wyam.Tables.Tests/CsvToHtmlFixture.cs @@ -14,7 +14,7 @@ public class CsvToHtmlFixture : BaseFixture public class ExecuteTests : CsvToHtmlFixture { [Test] - public void TestWithoutHeadder() + public void TestWithoutHeader() { // Given string input = string.Empty @@ -330,7 +330,7 @@ public void TestWithoutHeadder() } [Test] - public void TestHeadder() + public void TestHeader() { // Given string input = string.Empty diff --git a/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj b/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj index f45852386..502a98e76 100644 --- a/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj +++ b/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj @@ -10,7 +10,7 @@ - + From c5c4573ca96c1adb2948f6f11013064d02e895cd Mon Sep 17 00:00:00 2001 From: Dan Friedman Date: Wed, 30 May 2018 21:36:33 -0500 Subject: [PATCH 2/3] Add unit tests for CsvToMarkdown --- .../Wyam.Tables.Tests/CsvToMarkdownFixture.cs | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 tests/extensions/Wyam.Tables.Tests/CsvToMarkdownFixture.cs diff --git a/tests/extensions/Wyam.Tables.Tests/CsvToMarkdownFixture.cs b/tests/extensions/Wyam.Tables.Tests/CsvToMarkdownFixture.cs new file mode 100644 index 000000000..2bdf8c712 --- /dev/null +++ b/tests/extensions/Wyam.Tables.Tests/CsvToMarkdownFixture.cs @@ -0,0 +1,217 @@ +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Wyam.Common.Documents; +using Wyam.Testing; +using Wyam.Testing.Documents; +using Wyam.Testing.Execution; + +namespace Wyam.Tables.Tests +{ + [TestFixture] + public class CsvToMarkdownFixture : BaseFixture + { + public class ExecuteTests : CsvToMarkdownFixture + { + [Test] + public void TestWithoutHeader() + { + // Given + string input = string.Empty + + "\"\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"\r\n" ++ "\"1\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\"\r\n" ++ "\"2\",\"2\",\"4\",\"6\",\"8\",\"10\",\"12\",\"14\"\r\n" ++ "\"3\",\"3\",\"6\",\"9\",\"12\",\"15\",\"18\",\"21\"\r\n" ++ "\"4\",\"4\",\"8\",\"12\",\"16\",\"20\",\"24\",\"28\"\r\n" ++ "\"5\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\"\r\n" ++ "\"6\",\"6\",\"12\",\"18\",\"24\",\"30\",\"36\",\"42\"\r\n" ++ "\"7\",\"7\",\"14\",\"21\",\"28\",\"35\",\"42\",\"49\"\r\n" ++ "\"8\",\"8\",\"16\",\"24\",\"32\",\"40\",\"48\",\"56\"\r\n" ++ "\"9\",\"9\",\"18\",\"27\",\"36\",\"45\",\"54\",\"63\"\r\n" ++ "\"10\",\"10\",\"20\",\"30\",\"40\",\"50\",\"60\",\"70\"\r\n" ++ "\"11\",\"11\",\"22\",\"33\",\"44\",\"55\",\"66\",\"77\"\r\n" ++ "\"12\",\"12\",\"24\",\"36\",\"48\",\"60\",\"72\",\"84\"\r\n" ++ "\"13\",\"13\",\"26\",\"39\",\"52\",\"65\",\"78\",\"91\"\r\n" ++ "\"14\",\"14\",\"28\",\"42\",\"56\",\"70\",\"84\",\"98\"\r\n" ++ "\"15\",\"15\",\"30\",\"45\",\"60\",\"75\",\"90\",\"105\"\r\n" ++ "\"16\",\"16\",\"32\",\"48\",\"64\",\"80\",\"96\",\"112\"\r\n" ++ "\"17\",\"17\",\"34\",\"51\",\"68\",\"85\",\"102\",\"119\"\r\n" ++ "\"18\",\"18\",\"36\",\"54\",\"72\",\"90\",\"108\",\"126\"\r\n" ++ "\"19\",\"19\",\"38\",\"57\",\"76\",\"95\",\"114\",\"133\"\r\n" ++ "\"20\",\"20\",\"40\",\"60\",\"80\",\"100\",\"120\",\"140\"\r\n" ++ "\"21\",\"21\",\"42\",\"63\",\"84\",\"105\",\"126\",\"147\"\r\n" ++ "\"22\",\"22\",\"44\",\"66\",\"88\",\"110\",\"132\",\"154\"\r\n" ++ "\"23\",\"23\",\"46\",\"69\",\"92\",\"115\",\"138\",\"161\"\r\n" ++ "\"24\",\"24\",\"48\",\"72\",\"96\",\"120\",\"144\",\"168\"\r\n" ++ "\"25\",\"25\",\"50\",\"75\",\"100\",\"125\",\"150\",\"175\"\r\n" ++ "\"26\",\"26\",\"52\",\"78\",\"104\",\"130\",\"156\",\"182\"\r\n"; + + string output = @"+----+----+----+----+-----+-----+-----+-----+ +| | A | B | C | D | E | F | G | ++----+----+----+----+-----+-----+-----+-----+ +| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ++----+----+----+----+-----+-----+-----+-----+ +| 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | ++----+----+----+----+-----+-----+-----+-----+ +| 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | ++----+----+----+----+-----+-----+-----+-----+ +| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | ++----+----+----+----+-----+-----+-----+-----+ +| 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | ++----+----+----+----+-----+-----+-----+-----+ +| 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | ++----+----+----+----+-----+-----+-----+-----+ +| 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | ++----+----+----+----+-----+-----+-----+-----+ +| 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | ++----+----+----+----+-----+-----+-----+-----+ +| 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | ++----+----+----+----+-----+-----+-----+-----+ +| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | ++----+----+----+----+-----+-----+-----+-----+ +| 11 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | ++----+----+----+----+-----+-----+-----+-----+ +| 12 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | ++----+----+----+----+-----+-----+-----+-----+ +| 13 | 13 | 26 | 39 | 52 | 65 | 78 | 91 | ++----+----+----+----+-----+-----+-----+-----+ +| 14 | 14 | 28 | 42 | 56 | 70 | 84 | 98 | ++----+----+----+----+-----+-----+-----+-----+ +| 15 | 15 | 30 | 45 | 60 | 75 | 90 | 105 | ++----+----+----+----+-----+-----+-----+-----+ +| 16 | 16 | 32 | 48 | 64 | 80 | 96 | 112 | ++----+----+----+----+-----+-----+-----+-----+ +| 17 | 17 | 34 | 51 | 68 | 85 | 102 | 119 | ++----+----+----+----+-----+-----+-----+-----+ +| 18 | 18 | 36 | 54 | 72 | 90 | 108 | 126 | ++----+----+----+----+-----+-----+-----+-----+ +| 19 | 19 | 38 | 57 | 76 | 95 | 114 | 133 | ++----+----+----+----+-----+-----+-----+-----+ +| 20 | 20 | 40 | 60 | 80 | 100 | 120 | 140 | ++----+----+----+----+-----+-----+-----+-----+ +| 21 | 21 | 42 | 63 | 84 | 105 | 126 | 147 | ++----+----+----+----+-----+-----+-----+-----+ +| 22 | 22 | 44 | 66 | 88 | 110 | 132 | 154 | ++----+----+----+----+-----+-----+-----+-----+ +| 23 | 23 | 46 | 69 | 92 | 115 | 138 | 161 | ++----+----+----+----+-----+-----+-----+-----+ +| 24 | 24 | 48 | 72 | 96 | 120 | 144 | 168 | ++----+----+----+----+-----+-----+-----+-----+ +| 25 | 25 | 50 | 75 | 100 | 125 | 150 | 175 | ++----+----+----+----+-----+-----+-----+-----+ +| 26 | 26 | 52 | 78 | 104 | 130 | 156 | 182 | ++----+----+----+----+-----+-----+-----+-----+ +"; + TestExecutionContext context = new TestExecutionContext(); + TestDocument document = new TestDocument(input); + CsvToMarkdown module = new CsvToMarkdown(); + + // When + IList results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list + + // Then + Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { output })); + } + + [Test] + public void TestHeader() + { + // Given + string input = string.Empty + + "\"\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"\r\n" ++ "\"1\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\"\r\n" ++ "\"2\",\"2\",\"4\",\"6\",\"8\",\"10\",\"12\",\"14\"\r\n" ++ "\"3\",\"3\",\"6\",\"9\",\"12\",\"15\",\"18\",\"21\"\r\n" ++ "\"4\",\"4\",\"8\",\"12\",\"16\",\"20\",\"24\",\"28\"\r\n" ++ "\"5\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\"\r\n" ++ "\"6\",\"6\",\"12\",\"18\",\"24\",\"30\",\"36\",\"42\"\r\n" ++ "\"7\",\"7\",\"14\",\"21\",\"28\",\"35\",\"42\",\"49\"\r\n" ++ "\"8\",\"8\",\"16\",\"24\",\"32\",\"40\",\"48\",\"56\"\r\n" ++ "\"9\",\"9\",\"18\",\"27\",\"36\",\"45\",\"54\",\"63\"\r\n" ++ "\"10\",\"10\",\"20\",\"30\",\"40\",\"50\",\"60\",\"70\"\r\n" ++ "\"11\",\"11\",\"22\",\"33\",\"44\",\"55\",\"66\",\"77\"\r\n" ++ "\"12\",\"12\",\"24\",\"36\",\"48\",\"60\",\"72\",\"84\"\r\n" ++ "\"13\",\"13\",\"26\",\"39\",\"52\",\"65\",\"78\",\"91\"\r\n" ++ "\"14\",\"14\",\"28\",\"42\",\"56\",\"70\",\"84\",\"98\"\r\n" ++ "\"15\",\"15\",\"30\",\"45\",\"60\",\"75\",\"90\",\"105\"\r\n" ++ "\"16\",\"16\",\"32\",\"48\",\"64\",\"80\",\"96\",\"112\"\r\n" ++ "\"17\",\"17\",\"34\",\"51\",\"68\",\"85\",\"102\",\"119\"\r\n" ++ "\"18\",\"18\",\"36\",\"54\",\"72\",\"90\",\"108\",\"126\"\r\n" ++ "\"19\",\"19\",\"38\",\"57\",\"76\",\"95\",\"114\",\"133\"\r\n" ++ "\"20\",\"20\",\"40\",\"60\",\"80\",\"100\",\"120\",\"140\"\r\n" ++ "\"21\",\"21\",\"42\",\"63\",\"84\",\"105\",\"126\",\"147\"\r\n" ++ "\"22\",\"22\",\"44\",\"66\",\"88\",\"110\",\"132\",\"154\"\r\n" ++ "\"23\",\"23\",\"46\",\"69\",\"92\",\"115\",\"138\",\"161\"\r\n" ++ "\"24\",\"24\",\"48\",\"72\",\"96\",\"120\",\"144\",\"168\"\r\n" ++ "\"25\",\"25\",\"50\",\"75\",\"100\",\"125\",\"150\",\"175\"\r\n" ++ "\"26\",\"26\",\"52\",\"78\",\"104\",\"130\",\"156\",\"182\"\r\n"; + + string output = @"+----+----+----+----+-----+-----+-----+-----+ +| | A | B | C | D | E | F | G | ++====+====+====+====+=====+=====+=====+=====+ +| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ++----+----+----+----+-----+-----+-----+-----+ +| 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | ++----+----+----+----+-----+-----+-----+-----+ +| 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | ++----+----+----+----+-----+-----+-----+-----+ +| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | ++----+----+----+----+-----+-----+-----+-----+ +| 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | ++----+----+----+----+-----+-----+-----+-----+ +| 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | ++----+----+----+----+-----+-----+-----+-----+ +| 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | ++----+----+----+----+-----+-----+-----+-----+ +| 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | ++----+----+----+----+-----+-----+-----+-----+ +| 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | ++----+----+----+----+-----+-----+-----+-----+ +| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | ++----+----+----+----+-----+-----+-----+-----+ +| 11 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | ++----+----+----+----+-----+-----+-----+-----+ +| 12 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | ++----+----+----+----+-----+-----+-----+-----+ +| 13 | 13 | 26 | 39 | 52 | 65 | 78 | 91 | ++----+----+----+----+-----+-----+-----+-----+ +| 14 | 14 | 28 | 42 | 56 | 70 | 84 | 98 | ++----+----+----+----+-----+-----+-----+-----+ +| 15 | 15 | 30 | 45 | 60 | 75 | 90 | 105 | ++----+----+----+----+-----+-----+-----+-----+ +| 16 | 16 | 32 | 48 | 64 | 80 | 96 | 112 | ++----+----+----+----+-----+-----+-----+-----+ +| 17 | 17 | 34 | 51 | 68 | 85 | 102 | 119 | ++----+----+----+----+-----+-----+-----+-----+ +| 18 | 18 | 36 | 54 | 72 | 90 | 108 | 126 | ++----+----+----+----+-----+-----+-----+-----+ +| 19 | 19 | 38 | 57 | 76 | 95 | 114 | 133 | ++----+----+----+----+-----+-----+-----+-----+ +| 20 | 20 | 40 | 60 | 80 | 100 | 120 | 140 | ++----+----+----+----+-----+-----+-----+-----+ +| 21 | 21 | 42 | 63 | 84 | 105 | 126 | 147 | ++----+----+----+----+-----+-----+-----+-----+ +| 22 | 22 | 44 | 66 | 88 | 110 | 132 | 154 | ++----+----+----+----+-----+-----+-----+-----+ +| 23 | 23 | 46 | 69 | 92 | 115 | 138 | 161 | ++----+----+----+----+-----+-----+-----+-----+ +| 24 | 24 | 48 | 72 | 96 | 120 | 144 | 168 | ++----+----+----+----+-----+-----+-----+-----+ +| 25 | 25 | 50 | 75 | 100 | 125 | 150 | 175 | ++----+----+----+----+-----+-----+-----+-----+ +| 26 | 26 | 52 | 78 | 104 | 130 | 156 | 182 | ++----+----+----+----+-----+-----+-----+-----+ +"; + TestExecutionContext context = new TestExecutionContext(); + TestDocument document = new TestDocument(input); + CsvToMarkdown module = new CsvToMarkdown().WithHeader(); + + // When + IList results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list + + // Then + Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { output })); + } + } + } +} \ No newline at end of file From 30b8e14ed700e757704bb4f5276d37ca8eb7c518 Mon Sep 17 00:00:00 2001 From: Dan Friedman Date: Wed, 30 May 2018 22:03:40 -0500 Subject: [PATCH 3/3] Target .NET Standard and .NET Standard --- src/extensions/Wyam.Tables/ExcelFile.cs | 3 +- src/extensions/Wyam.Tables/Wyam.Tables.csproj | 2 +- .../Wyam.Tables.Tests.csproj | 55 +------------------ 3 files changed, 4 insertions(+), 56 deletions(-) diff --git a/src/extensions/Wyam.Tables/ExcelFile.cs b/src/extensions/Wyam.Tables/ExcelFile.cs index 95f1926e6..46197cced 100644 --- a/src/extensions/Wyam.Tables/ExcelFile.cs +++ b/src/extensions/Wyam.Tables/ExcelFile.cs @@ -7,10 +7,11 @@ namespace Wyam.Tables { internal static class ExcelFile { - public static IEnumerable> GetAllRecords(Stream stream, int sheetNumber = 1) + public static IEnumerable> GetAllRecords(Stream stream, int sheetNumber = 0) { using (var excel = new ExcelPackage(stream)) { + excel.Compatibility.IsWorksheets1Based = false; if (sheetNumber > excel.Workbook.Worksheets.Count) { return null; diff --git a/src/extensions/Wyam.Tables/Wyam.Tables.csproj b/src/extensions/Wyam.Tables/Wyam.Tables.csproj index cc9ef1253..d8dfcac03 100644 --- a/src/extensions/Wyam.Tables/Wyam.Tables.csproj +++ b/src/extensions/Wyam.Tables/Wyam.Tables.csproj @@ -1,6 +1,6 @@  - net462 + netstandard2.0 Wyam is a simple to use, highly modular, and extremely configurable static content generator. This library provides support for importing and exporting CSV and Excel files. Wyam Static StaticContent StaticSite Blog BlogEngine CSV Excel diff --git a/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj b/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj index 502a98e76..3ede03fb4 100644 --- a/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj +++ b/tests/extensions/Wyam.Tables.Tests/Wyam.Tables.Tests.csproj @@ -1,6 +1,6 @@  - net462 + netcoreapp2.0 @@ -11,64 +11,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{cell.Value}{cell}{cell.Value}{cell}