Skip to content
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v1.9.0
with:
dotnet-version: 3.1.x
dotnet-version: 6.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
name: build, pack & publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v1.9.0
with:
dotnet-version: 3.1.x
dotnet-version: 6.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand All @@ -23,7 +23,7 @@ jobs:
# Publish
- name: publish on version change
id: publish_nuget
uses: rohith/publish-nuget@v2
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: FastExcel/FastExcel.csproj
NUGET_KEY: ${{secrets.NUGET_KEY}}
Expand Down
17 changes: 7 additions & 10 deletions FastExcel.Tests/FastExcel.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0-preview-20211130-02" />
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FastExcel\FastExcel.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="ResourcesTests\OneRowFile.xlsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -33,5 +31,4 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
48 changes: 24 additions & 24 deletions FastExcel.Tests/FastExcelTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

using Xunit;
using Xunit.Abstractions;

Expand All @@ -14,7 +13,7 @@ public class FastExcelTests
private static readonly string ResourcesPath = Path.Combine(Environment.CurrentDirectory, "ResourcesTests");
private static readonly string TemplateFilePath = Path.Combine(ResourcesPath, "template.xlsx");

private static readonly CellRow TestCellRow = new CellRow()
private static readonly CellRow TestCellRow = new()
{
StringColumn1 = "&",
IntegerColumn2 = 45678854,
Expand All @@ -37,7 +36,7 @@ public void FileNotExist_NewFastExcelWithInvalidInputFile_ThrowsFileNotFoundExce

var action = new Action(() =>
{
using (var fastExcel = new FastExcel(inputFile)) ;
using FastExcel fastExcel = new(inputFile);
});

var exception = Assert.Throws<FileNotFoundException>(action);
Expand All @@ -55,7 +54,7 @@ public void FileNotExist_NewFastExcelWithInvalidTemplateFile_ThrowsFileNotFoundE

var action = new Action(() =>
{
using (var fastExcel = new FastExcel(templateFile, outputFile)) ;
using FastExcel fastExcel = new(templateFile, outputFile);
});

var exception = Assert.Throws<FileNotFoundException>(action);
Expand All @@ -73,7 +72,7 @@ public void FilesExist_NewFastExcelWithExistOutputFile_ThrowsFileNotFoundExcepti

var action = new Action(() =>
{
using (var fastExcel = new FastExcel(templateFile, outputFile)) ;
using FastExcel fastExcel = new(templateFile, outputFile);
});

var exception = Assert.Throws<Exception>(action);
Expand All @@ -88,10 +87,8 @@ public void InputFile_ReadExcelWithNullReference_ExceptionIsNull()

var action = new Action(() =>
{
using (var fastExcel = new FastExcel(inputFile, true))
{
var worksheet = fastExcel.Read(1, 1);
}
using FastExcel fastExcel = new(inputFile, true);
var worksheet = fastExcel.Read(1, 1);
});

var exception = Record.Exception(action);
Expand All @@ -101,19 +98,23 @@ public void InputFile_ReadExcelWithNullReference_ExceptionIsNull()
[Fact]
public void ThrowsErrorIfInitializedWithStreamAndFileInfoIsAccessed()
{
using var inputMemorystream = new MemoryStream(new byte[] {0x1});
using var inputMemorystream = new MemoryStream(new byte[] { 0x1 });
using var outputMemorystream = new MemoryStream();

var fastExcel = new FastExcel(inputMemorystream, outputMemorystream);
var exception = Assert.Throws<ApplicationException>(() => fastExcel.ExcelFile);
Assert.Equal($"ExcelFile was not provided", exception.Message);

Assert.Equal("ExcelFile was not provided", exception.Message);
exception = Assert.Throws<ApplicationException>(() => fastExcel.TemplateFile);
Assert.Equal($"TemplateFile was not provided", exception.Message);

Assert.Equal("TemplateFile was not provided", exception.Message);
}

private string FileRead_ReadingSpecialCharactersCore_Read(FileInfo inputFile)
{
inputFile.Refresh();
using var fastExcel = new FastExcel(inputFile);

var worksheet = fastExcel.Read("sheet1");
var rows = worksheet.Rows;

Expand All @@ -132,15 +133,13 @@ private string FileRead_ReadingSpecialCharactersCore_Read(FileInfo inputFile)
return "Passed";
}


[Fact]
public string FileRead_ReadingSpecialCharacters_Read()
{
var inputFilePath = new FileInfo(Path.Combine(ResourcesPath, "special-char.xlsx"));
return FileRead_ReadingSpecialCharactersCore_Read(inputFilePath);
}


[Fact]
public string FileWrite_WritingOneRow_Wrote()
{
Expand All @@ -151,22 +150,23 @@ public string FileWrite_WritingOneRow_Wrote()
var templateFilePath = new FileInfo(TemplateFilePath);
using (var fastExcel = new FastExcel(templateFilePath, inputFilePath))
{
List<CellRow> objectList = new List<CellRow>();
List<CellRow> objectList = new();

objectList.Add(TestCellRow);
fastExcel.Write(objectList, "sheet1", true);
}


return FileRead_ReadingSpecialCharactersCore_Read(inputFilePath);
}

[Fact]
public string FileUpdate_UpdatingEmptyFile_Updated()
{
var worksheet = new Worksheet();
var cells = new List<CellRow>();
cells.Add(TestCellRow);
var cells = new List<CellRow>
{
TestCellRow
};

worksheet.PopulateRows(cells, usePropertiesAsHeadings: true);
var templateFile = new FileInfo(TemplateFilePath);
Expand All @@ -178,15 +178,14 @@ public string FileUpdate_UpdatingEmptyFile_Updated()
fastExcel.Update(worksheet, "Sheet1");
}


return FileRead_ReadingSpecialCharactersCore_Read(inputFile);
}

[Fact]
public string FileUpdate_UpdatingWithOneRow_Updated()
{
var worksheet = new Worksheet();
var cells = new List<CellRow> {TestCellRow};
var cells = new List<CellRow> { TestCellRow };

worksheet.PopulateRows(cells, usePropertiesAsHeadings: true);

Expand All @@ -204,8 +203,10 @@ public string FileUpdate_UpdatingWithOneRow_Updated()
public string FileUpdate_WriteAndUpdatingWithOneRow_Updated()
{
var worksheet = new Worksheet();
var cells = new List<CellRow>();
cells.Add(TestCellRow);
var cells = new List<CellRow>
{
TestCellRow
};

worksheet.PopulateRows(cells, usePropertiesAsHeadings: true);

Expand All @@ -217,7 +218,6 @@ public string FileUpdate_WriteAndUpdatingWithOneRow_Updated()
inputFile.Refresh();
}


//Writing Data One Row
using (var fastExcel = new FastExcel(templateFile, inputFile))
{
Expand Down
20 changes: 11 additions & 9 deletions FastExcel/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FastExcel
public class Cell
{
/// <summary>
/// Column Numnber (Starts at 1)
/// Column Number (Starts at 1)
/// </summary>
public int ColumnNumber { get; set; }

Expand All @@ -26,12 +26,12 @@ public class Cell
/// Defined name or the column letter(s) for column this cell is in
/// </summary>
public string ColumnName { get; }

/// <summary>
/// Raw underlying XElement of cell
/// </summary>
public XElement XElement { get; }

/// <summary>
/// List of defined names assigned to this cell
/// *Does not include names of ranges this cell is within*
Expand All @@ -45,8 +45,11 @@ public string CellName
{
get
{
if (CellNames.Any())
return CellNames.FirstOrDefault();
if (CellNames.Count > 0)
{
return CellNames[0];
}

return ColumnName + RowNumber;
}
}
Expand Down Expand Up @@ -106,7 +109,7 @@ public Cell(XElement cellElement, Worksheet worksheet)
{
// cellElement.Value will give a concatenated Value + reference/calculation

var node = cellElement.Elements().Where(x => x.Name.LocalName == "v").SingleOrDefault();
var node = cellElement.Elements().SingleOrDefault(x => x.Name.LocalName == "v");

if (node != null)
{
Expand All @@ -116,7 +119,6 @@ public Cell(XElement cellElement, Worksheet worksheet)
{
Value = cellElement.Value;
}

}
}

Expand Down Expand Up @@ -147,7 +149,7 @@ internal StringBuilder ToXmlString(SharedStrings sharedStrings, int rowNumber)
value = sharedStrings.AddString(value.ToString());
}

cell.AppendFormat("<c r=\"{0}{1}\"{2}>", GetExcelColumnName(ColumnNumber), rowNumber, (isString ? " t=\"s\"" : string.Empty));
cell.AppendFormat("<c r=\"{0}{1}\"{2}>", GetExcelColumnName(ColumnNumber), rowNumber, isString ? " t=\"s\"" : string.Empty);
cell.AppendFormat("<v>{0}</v>", value);
cell.Append("</c>");
}
Expand Down Expand Up @@ -215,7 +217,7 @@ public void Merge(Cell cell)
}

/// <summary>
///
/// Returns a cell's Value as a String
/// </summary>
/// <returns>Cell's Value</returns>
public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion FastExcel/CellRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal CellRange(string reference)
// Default value
RowStart = 1;

if (range.Contains(":"))
if (range.Contains(':'))
{
string[] splitRange = range.Split(':');
ColumnStart = splitRange[0].Split('$')[1];
Expand Down
3 changes: 1 addition & 2 deletions FastExcel/DefinedName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace FastExcel
{

/// <summary>
/// Reads/hold information from XElement representing a stored DefinedName
/// A defined name is an alias for a cell, multiple cells, a range of cells or multiple ranges of cells
Expand All @@ -23,7 +22,7 @@ internal DefinedName(XElement e)
{
try
{
WorksheetIndex = Convert.ToInt32(e.Attribute("localSheetId").Value)+1;
WorksheetIndex = Convert.ToInt32(e.Attribute("localSheetId").Value) + 1;
}
catch (Exception exception)
{
Expand Down
15 changes: 14 additions & 1 deletion FastExcel/DefinedNameLoadException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace FastExcel
{

/// <summary>
/// Exception used during loading process of defined names
/// </summary>
Expand All @@ -14,7 +13,21 @@ public class DefinedNameLoadException : Exception
public DefinedNameLoadException(string message, Exception innerException = null)
: base(message, innerException)
{
}

/// <summary>
/// Constructor
/// </summary>
public DefinedNameLoadException() : base()
{
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="message">message</param>
public DefinedNameLoadException(string message) : base(message)
{
}
}
}
1 change: 0 additions & 1 deletion FastExcel/DefinedNamesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace FastExcel
/// </summary>
internal static class DefinedNamesExtensions
{

/// <summary>
/// Finds all the cell names for a given cell
/// </summary>
Expand Down
Loading