Skip to content

Commit

Permalink
Merge pull request #35 from IowaComputerGurus/feature/release-prep
Browse files Browse the repository at this point in the history
Feature/release prep
  • Loading branch information
mitchelsellers authored Jun 10, 2022
2 parents 0081f69 + 38e7c0e commit 12662f8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,28 @@ var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition)
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);
```

## Sample Multi-Sheet Document Export

A streamlined fluent syntax is available to export multiple sheets of content.

```csharp
var multiSheetDefinition = new MultisheetConfiguration()
.WithSheet("Sheet 1", GetSampleExportData(100))
.WithSheet("Additional Sheet", GetSampleExportData(500), config =>
{
config.DocumentTitle = "Lots of data";
config.RenderTitle = true;
});

var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition);
System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
```

## Key Features
This package is primarily geared towards the exporting of lists of objects into excel sheets. The following key features are supported.

* The ability to have one, or more, sheets of data exported
* The ability to have a heading and subheading if desired
* Data type formatting for Date & Currency fields
* Auto-fit of all columns for display
* Auto-fit of all columns for display
* Support for Curreny, Date, F0, F1, and F2 fixed date formats
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DocumentFOrmat.OpenXml" Version="2.14.0" />
<PackageReference Include="DocumentFOrmat.OpenXml" Version="2.16.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>

Expand Down
22 changes: 10 additions & 12 deletions samples/NetCore.Utilities.SpreadsheetExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ static void Main(string[] args)
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);

var multiSheet = new List<ISpreadsheetConfiguration<object>>();
multiSheet.Add(exportDefinition);
multiSheet.Add(new SpreadsheetConfiguration<SimpleExportData>
{
RenderTitle = true,
DocumentTitle = "Sample Second of 50 Records",
RenderSubTitle = true,
DocumentSubTitle = "Showing the full options",
ExportData = GetSampleExportData(50),
WorksheetName = "Additional"
});
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheet);
//Sample 2 sheet export
var multiSheetDefinition = new MultisheetConfiguration()
.WithSheet("Sheet 1", GetSampleExportData(100))
.WithSheet("Additional Sheet", GetSampleExportData(500), config =>
{
config.DocumentTitle = "Lots of data";
config.RenderTitle = true;
});

var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition);
System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
Console.WriteLine("Files Created");
Console.ReadLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.1" />
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.14.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
11 changes: 4 additions & 7 deletions src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public bool CreateMultiSheetSpreadsheet(Stream output, IEnumerable<ISpreadsheetC
var spreadsheetDocument = SpreadsheetDocument.Create(output, SpreadsheetDocumentType.Workbook);
var workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
Debug.Assert(spreadsheetDocument.WorkbookPart != null, "spreadsheetDocument.WorkbookPart != null. Something must be wrong with the universe.");
var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());

//Setup our styles
Expand Down Expand Up @@ -239,6 +238,7 @@ private static SheetData CreateExportSheet(ISpreadsheetConfiguration exportConfi
StyleIndex = (int)FontStyleIndex.DataHeader
};
headerRow.Append(headerCell);
outputMap[prop].Cells.Add(headerCell);
}

data.Append(headerRow);
Expand Down Expand Up @@ -269,10 +269,7 @@ private static SheetData CreateExportSheet(ISpreadsheetConfiguration exportConfi
data.Append(dataRow);
currentRow++;
}

//Auto-size
//columns = AutoSize(data);


if (exportConfiguration.AutoSizeColumns)
{
CalculateSizes(outputMap.Values.ToList());
Expand Down Expand Up @@ -449,8 +446,8 @@ private static int GetMaxCharacterWidth(IList<Cell> cells)
//iterate over all cells getting a max char value for each column
var maxWidth = 0;

//TODO: Be smarter about this for our set styles
var numberStyles = new UInt32[] { 5, 6, 7, 8 }; //styles that will add extra chars
//TODO: Adjust this to use Enum & Validate all style formats
var numberStyles = new UInt32[] { 7, 8 }; //styles that will add extra chars
var boldStyles = new UInt32[] { 1, 2, 3, 4, 6, 7, 8 }; //styles that will bold

//using cell index as my column
Expand Down

0 comments on commit 12662f8

Please sign in to comment.