Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
changelog:
exclude:
labels:
- question
- wontfix
- invalid
categories:
- title: Exciting New Features 🎉
labels:
- enhancement
- feature
- title: Squashed Bugs 🐛
labels:
- bug
- breaking-change
- title: Administrative
labels:
- administrative
- documentation
- dependencies
- title: Other Changes
labels:
- "*"
22 changes: 9 additions & 13 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ jobs:
dotnet-version: 9.0.x

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.2.1
uses: gittools/actions/gitversion/setup@v4.2.0
with:
versionSpec: '6.0.5'

versionSpec: '6.4.0'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.2.1
with:
useConfigFile: true
uses: gittools/actions/gitversion/execute@v4.2.0

- name: Restore Packages
run: dotnet restore "${{ env.solution-path }}"
Expand Down Expand Up @@ -81,24 +79,22 @@ jobs:
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.2.1
uses: gittools/actions/gitversion/setup@v4.2.0
with:
versionSpec: '6.0.5'
versionSpec: '6.4.0'

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.2.1
with:
useConfigFile: true
uses: gittools/actions/gitversion/execute@v4.2.0

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"IowaComputerGurus_netcore.utilities.spreadsheet" /o:"iowacomputergurus-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
.\.sonar\scanner\dotnet-sonarscanner begin /k:"IowaComputerGurus_netcore.utilities.spreadsheet" /o:"iowacomputergurus-github" /d:sonar.token="${{ env.SONAR_TOKEN }}"
dotnet restore "${{ env.solution-path }}"
dotnet build "${{ env.solution-path }}" --no-restore --configuration Release -p:version=${{ steps.gitversion.outputs.majorMinorPatch }}
dotnet test "${{ env.solution-path }}" --no-build --configuration Release --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --logger "trx;LogFileName=unittests.trx"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ env.SONAR_TOKEN }}"
10 changes: 4 additions & 6 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ jobs:
dotnet-version: 9.0.x

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.2.1
uses: gittools/actions/gitversion/setup@v4.2.0
with:
versionSpec: '6.0.5'

versionSpec: '6.4.0'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.2.1
with:
useConfigFile: true
uses: gittools/actions/gitversion/execute@v4.2.0

- name: Restore Packages
run: dotnet restore "${{ env.solution-path }}"
Expand Down
1 change: 0 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ branches:
pull-request:
regex: (pull|pull\-requests|pr)[/-]
label: 'pr'
label-number-pattern: '[/-](?<number>\d+)[-/]'
increment: Patch
is-release-branch: false
source-branches: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DocumentFOrmat.OpenXml" Version="2.16.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
</ItemGroup>

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.2" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="Bogus" Version="35.6.5" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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.5">
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.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,9 +34,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<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 @@ -46,7 +46,7 @@ public bool CreateSingleSheetSpreadsheet<T>(Stream output, SpreadsheetConfigurat
nameof(exportConfiguration.DocumentSubTitle));

//Create the document & overall workbook
var spreadsheetDocument = SpreadsheetDocument.Create(output, SpreadsheetDocumentType.Workbook);
using var spreadsheetDocument = SpreadsheetDocument.Create(output, SpreadsheetDocumentType.Workbook);

var workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
Expand Down Expand Up @@ -87,7 +87,6 @@ public bool CreateSingleSheetSpreadsheet<T>(Stream output, SpreadsheetConfigurat
sheets.Append(sheet);

workbookPart.Workbook.Save();
spreadsheetDocument.Close();
return true;

}
Expand Down Expand Up @@ -157,10 +156,10 @@ public bool CreateMultiSheetSpreadsheet(Stream output, IEnumerable<ISpreadsheetC
throw new ArgumentNullException(nameof(exportSheets));

//Create the document & overall workbook
var spreadsheetDocument = SpreadsheetDocument.Create(output, SpreadsheetDocumentType.Workbook);
using var spreadsheetDocument = SpreadsheetDocument.Create(output, SpreadsheetDocumentType.Workbook);
var workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());

//Setup our styles
var stylesPart = spreadsheetDocument.WorkbookPart.AddNewPart<WorkbookStylesPart>();
Expand Down Expand Up @@ -199,9 +198,9 @@ public bool CreateMultiSheetSpreadsheet(Stream output, IEnumerable<ISpreadsheetC
sheets.Append(sheet);
sheetId++;
}

//Save off the file
workbookPart.Workbook.Save();
spreadsheetDocument.Close();

return true;
}
Expand Down
63 changes: 30 additions & 33 deletions src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
Sheet sheet;
if (worksheetNumber.HasValue)
{
sheet = workbookPart.Workbook.Descendants<Sheet>().Skip(worksheetNumber.Value - 1).FirstOrDefault();

Check warning on line 67 in src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetParser.cs

View workflow job for this annotation

GitHub Actions / Analyze Code Quality

Converting null literal or possible null value to non-nullable type.

Check warning on line 67 in src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetParser.cs

View workflow job for this annotation

GitHub Actions / Analyze Code Quality

Converting null literal or possible null value to non-nullable type.

Check warning on line 67 in src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetParser.cs

View workflow job for this annotation

GitHub Actions / Validate Build

Converting null literal or possible null value to non-nullable type.

Check warning on line 67 in src/NetCore.Utilities.Spreadsheet/OpenXmlSpreadsheetParser.cs

View workflow job for this annotation

GitHub Actions / Validate Build

Converting null literal or possible null value to non-nullable type.
if (sheet == null) throw new SpreadsheetParserException($"Workbook does not have {worksheetNumber} sheets");
}
else
Expand Down Expand Up @@ -155,42 +155,39 @@
return cell.InnerText;

string value = cell.InnerText;
switch (cell.DataType.Value)
if (cell.DataType.Value == CellValues.SharedString)
{
case CellValues.SharedString:
// For shared strings, look up the value in the shared strings table.
// Get worksheet from cell
Debug.Assert(cell.Parent != null, "cell.Parent != null");
OpenXmlElement parent = cell.Parent;
while (parent.Parent != null && parent.Parent != parent
&& string.Compare(parent.LocalName, "worksheet", StringComparison.OrdinalIgnoreCase) != 0)
{
parent = parent.Parent;
}
if (string.Compare(parent.LocalName, "worksheet", StringComparison.OrdinalIgnoreCase) != 0)
{
throw new SpreadsheetParserException($"Unable to find parent worksheet of cell {cell}");
}
// For shared strings, look up the value in the shared strings table.
// Get worksheet from cell
Debug.Assert(cell.Parent != null, "cell.Parent != null");
OpenXmlElement parent = cell.Parent;
while (parent.Parent != null && parent.Parent != parent
&& string.Compare(parent.LocalName, "worksheet", StringComparison.OrdinalIgnoreCase) != 0)
{
parent = parent.Parent;
}
if (string.Compare(parent.LocalName, "worksheet", StringComparison.OrdinalIgnoreCase) != 0)
{
throw new SpreadsheetParserException($"Unable to find parent worksheet of cell {cell}");
}

var ws = parent as Worksheet;
var ssDoc = ws?.WorksheetPart?.OpenXmlPackage as SpreadsheetDocument;
var sstPart = ssDoc?.WorkbookPart?.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
var ws = parent as Worksheet;
var ssDoc = ws?.WorksheetPart?.OpenXmlPackage as SpreadsheetDocument;
var sstPart = ssDoc?.WorkbookPart?.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();

return sstPart == null ? value : sstPart.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
//this case within a case is copied from msdn.
case CellValues.Boolean:
return value switch
{
"0" => "FALSE",
_ => "TRUE"
};
case CellValues.Number:
case CellValues.Error:
case CellValues.String:
case CellValues.InlineString:
case CellValues.Date:
default:
return value;
return sstPart == null ? value : sstPart.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
}

if (cell.DataType.Value == CellValues.Boolean)
{
return value switch
{
"0" => "FALSE",
_ => "TRUE"
};
}

//All other types return the value
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SpreadsheetColumnAttribute : Attribute
/// <param name="width">Sets the width of the column</param>
/// <param name="ignore">If true, the column will be excluded from the spreadsheet</param>
/// <param name="format">Sets the format of the column data</param>
/// <param name="formula">Sets a specific formula to be utilized by this column</param>
public SpreadsheetColumnAttribute(string displayName = null, float width = 0, bool ignore = false,
string format = null, string formula = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#nullable enable
using System;
using System.Runtime.Serialization;

namespace ICG.NetCore.Utilities.Spreadsheet;

Expand All @@ -10,11 +9,6 @@ namespace ICG.NetCore.Utilities.Spreadsheet;
[Serializable]
public class SpreadsheetParserException : Exception
{
/// <inheritdoc />
protected SpreadsheetParserException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

internal SpreadsheetParserException(string message) : base(message)
{

Expand Down