YGMSExcelBeater 1.7.0
dotnet add package YGMSExcelBeater --version 1.7.0
NuGet\Install-Package YGMSExcelBeater -Version 1.7.0
<PackageReference Include="YGMSExcelBeater" Version="1.7.0" />
<PackageVersion Include="YGMSExcelBeater" Version="1.7.0" />
<PackageReference Include="YGMSExcelBeater" />
paket add YGMSExcelBeater --version 1.7.0
#r "nuget: YGMSExcelBeater, 1.7.0"
#addin nuget:?package=YGMSExcelBeater&version=1.7.0
#tool nuget:?package=YGMSExcelBeater&version=1.7.0
README
What is this repository for?
This class libary uses NPOI to read and write to excel file with c# .net 6 and above. It has internal mapper to map the contents of Excel sheet to a generic collection List<T> as long as the property names match the field names in the excel file. The header row must be the first row and data must start from the first column, second row
How do I get set up?
The Excel file must have a header to hold the field names. The field names must not have spaces or special characters All field names must be reproducable in the DTO where the records are mapped to
Sample setup: (Excel containing a key field in column 0 "L-2" being one of the unique values )
// Sample.xlsx is provided in the source code - just an excel file containing RecordID, Name, Title, IsActive, and DOB
string excelFileName = "C:\\Temp\\Sample.xlsx";
// Constructor takes filename, sheet number, and column number for the key, or, column name
using (IMSExcelBeater beater = new MSExcelBeater(excelFileName, 0, 0)) // first parm: filename, second parm: sheet number. Third parm: key column number or name
{
string[] fieldNames = beater.GetAllFieldNames(); // Use this function to retreve all field names and to construct the DTO
List<TestDTO> allData = beater.GetAllData<TestDTO>(); // This is to retrieve the entire sheet into a generic collection of DTO (that could be created using .GetAllFieldNames())
// This is to update the Excel file directly -----------------
string title = beater.Get("L-2", "title"); // This is to get a value from column "title" row key number "L-2"
string result1 = beater.Update("L-2", "title", "bloon"); // This is to update the value in column "title" row key number "L-2"
string result2 = beater.Save(); // This is to save all the updates. Remember to invoke .Save() to save your changes.
}
// Export DataSet to Excel:
string outputFilePath = @"C:\Temp\FakeDataSetOutput.xlsx";
// Export DataSet to Excel
using (IMSExcelBeater exporter = new MSExcelBeater(outputFilePath))
{
exporter.ExportDataSetToExcel(fakeDataSet);
}
Console.WriteLine($"Excel file created successfully at: {outputFilePath}");
using (IMSExcelBeater beater = new MSExcelBeater(excelFileName, 0, 0)) // first parm: filename, second parm: sheet number. Third parm: key column number or name
{
// Import Excel to DataTable
DataTable dt = beater.GetAllData();
//Import Excel to a known DTO
List<DTO> dtos = beater.GetAllData<DTO>();
}
Contribution guidelines
- Writing tests
- Code review
- Other guidelines
Who do I talk to?
- Repo owner or admin
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- NPOI (>= 2.7.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Handle missing first row in the constructor