Skip to content

Commit

Permalink
Rename from Excel to Export. More generic; Add case for null on ToStr…
Browse files Browse the repository at this point in the history
…ing(); Bump version;
  • Loading branch information
gabrieldelaparra committed Nov 18, 2021
1 parent c91a209 commit 5f54f40
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Wororo.Utilities.UnitTests/ExcelSerializationUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public void TestCreateSampleExcelFileFromTwoSheetModel()
"5,6,7,8",
"1,2,3,4"
};
var excelBook = new ExcelBookModel("testModel.xlsx");
var excelBook = new ExportBook("testModel.xlsx");

var sheet1 = new ExcelSheetModel("Sheet1", new[] {"A", "B", "C", "D"});
var sheet1 = new ExportSheet("Sheet1", new[] {"A", "B", "C", "D"});
sheet1.AddRow(new []{"1", "2", "3", "4"});
sheet1.AddRow(new[] { "5", "6", "7", "8" });
sheet1.AddRow(new[] { "1", "2", "3", "4" });
excelBook.Sheets.Add(sheet1);

var sheet2 = new ExcelSheetModel("Sheet2", new[] { "A", "B", "C", "D" });
var sheet2 = new ExportSheet("Sheet2", new[] { "A", "B", "C", "D" });
sheet2.AddRow(new[] { "5", "6", "7", "8" });
sheet2.AddRow(new[] { "1", "2", "3", "4" });
sheet2.AddRow(new[] { "5", "6", "7", "8" });
excelBook.Sheets.Add(sheet2);

excelBook.Save(true);
excelBook.SaveAsTSV();
excelBook.ExportToExcel(true);
excelBook.ExportToTSV();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MiniExcelLibs;

namespace Wororo.Utilities
{
public class ExcelBookModel
public class ExportBook
{
private readonly string _outputFilename;
public ExcelBookModel(string outputFilename)
public ExportBook(string outputFilename)
{
_outputFilename = outputFilename;
}

public IList<ExcelSheetModel> Sheets = new List<ExcelSheetModel>();
public IList<ExportSheet> Sheets = new List<ExportSheet>();

public IDictionary<string, object> GetSheetsDictionary(bool addNewSheetWithWorkSheetColumn = false)
public IDictionary<string, object> GetSheetsDictionary(bool createAllSummarySheet = false)
{
var dictionary = new Dictionary<string, object>();
foreach (var sheet in Sheets)
{
dictionary.Add(sheet.SheetName, sheet.ToDictionary());
}

if (addNewSheetWithWorkSheetColumn)
if (createAllSummarySheet)
{
var allRowsDictionary = new List<IDictionary<string, object>>();
foreach (var sheet in Sheets)
Expand All @@ -42,15 +41,15 @@ public IDictionary<string, object> GetSheetsDictionary(bool addNewSheetWithWorkS
return dictionary;
}

public void Save(bool saveAll = false)
public void ExportToExcel(bool createAllSummarySheet = false)
{
_outputFilename.CreatePathIfNotExists();
_outputFilename.DeleteIfExists();

MiniExcel.SaveAs(_outputFilename, GetSheetsDictionary(saveAll));
MiniExcel.SaveAs(_outputFilename, GetSheetsDictionary(createAllSummarySheet));
}

public void SaveAsTSV(bool naturalSortBefore = false)
public void ExportToTSV(bool naturalSortBefore = false)
{
foreach (var sheet in Sheets)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Wororo.Utilities
{
public class ExcelSheetModel
public class ExportSheet
{
public ExcelSheetModel(string sheetName, IEnumerable<string> headers)
public ExportSheet(string sheetName, IEnumerable<string> headers)
{
SheetName = sheetName;
Headers = headers.ToArray();
Expand Down
6 changes: 3 additions & 3 deletions Wororo.Utilities/Wororo.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<Authors>Gabriel De La Parra</Authors>
<Company>Wororo</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AssemblyVersion>1.2.1.8</AssemblyVersion>
<AssemblyVersion>1.2.1.9</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<FileVersion>1.2.1.8</FileVersion>
<FileVersion>1.2.1.9</FileVersion>
<PackageVersion>$(InformationalVersion)</PackageVersion>
<Version>1.2.1.8</Version>
<Version>1.2.1.9</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 5f54f40

Please sign in to comment.