StaticExcel 1.2.1

dotnet add package StaticExcel --version 1.2.1                
NuGet\Install-Package StaticExcel -Version 1.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StaticExcel" Version="1.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StaticExcel --version 1.2.1                
#r "nuget: StaticExcel, 1.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StaticExcel as a Cake Addin
#addin nuget:?package=StaticExcel&version=1.2.1

// Install StaticExcel as a Cake Tool
#tool nuget:?package=StaticExcel&version=1.2.1                

ExcelLib Documentation

ExcelLib Documentation

Overview

ExcelLib is a C# library designed to facilitate reading from and writing to Excel files using the EPPlus library. It supports operations like reading data frames from Excel sheets and writing lists of objects back into Excel. The library aims to be easy to use while providing robust functionality for handling Excel data in .NET applications.

Features

  • Read Excel Data: Load objects from Excel sheets into C# lists.
  • Write to Excel: Export lists of objects to new or existing Excel sheets.
  • Dynamic Property Mapping: Properties of objects are dynamically mapped to Excel columns based on custom attributes.
  • Type Conversion and Validation: Ensures that data conforms to expected types and formats, applying custom conversion rules as needed.

Installation

To use ExcelLib, you must first ensure that the EPPlus package is installed in your project as it is a dependency for handling Excel file operations.

Install-Package EPPlus -Version 5.x

Usage

Initializing the Library

var excelLib = new ExcelLib("path/to/excel/file.xlsx");

Reading from Excel

The ReadDataFrame method allows you to read data from a specified Excel sheet and map it to a list of objects of a specified type.

var data = excelLib.ReadDataFrame<MyModel>("Sheet1");

Writing to Excel

To write data to an Excel file, use the WriteDataFrame method. This method takes a list of objects and writes them to the specified Excel sheet.

excelLib.WriteDataFrame(data, "Sheet1");

Saving Changes

To save any changes made to the Excel file, use the Save or SaveAs method.

excelLib.Save();  // Saves changes to the original file
excelLib.SaveAs("path/to/new/file.xlsx");  // Saves changes to a new file

  ExcelLib Usage Examples

ExcelLib Usage Examples

Example Data Model Definitions

This section provides examples of defining models for inventory management and customer data processing.

Inventory Item Example

    public class InventoryItem : ExcelDataModel {
        [Excel(Name = "Item ID", CanBeNull = false)]
        public string ItemId { get; set; }
    
        [Excel(Name = "Description", CaseSensitive = false)]
        public string Description { get; set; }
    
        [Excel(Name = "Quantity", Type = typeof(int))]
        public int Quantity { get; set; }
    
        [Excel(Name = "Price", Type = typeof(decimal))]
        public decimal Price { get; set; }
    }
            

Customer Data Example

    public class Customer : ExcelDataModel {
        [Excel(Name = "Customer ID", CanBeNull = false)]
        public string CustomerId { get; set; }
    
        [Excel(Name = "Full Name")]
        public string FullName { get; set; }
    
        [Excel(Name = "Email Address", IgnoreCases = ["email", "mail"], CaseSensitive = false)]
        public string Email { get; set; }
    
        [Excel(Name = "Signup Date", Type = typeof(DateTime))]
        public DateTime SignupDate { get; set; }
    
        [Excel(Name = "Loyalty Points", Type = typeof(int), CanBeNull = true)]
        public int? LoyaltyPoints { get; set; }
    }

Explanation of Attributes

<a href="https://github.com/Lorefist5/Excel/tree/master/Excel.Library/Attributes">All attributes here</a>

Use Case: Reading Data

To utilize these models, instantiate ExcelLib, specify the Excel file, and use the ReadDataFrame method with the model type that matches your Excel layout.

    var excelLib = new ExcelLib("path/to/inventory/file.xlsx");
    var inventoryItems = excelLib.ReadDataFrame<InventoryItem>("InventorySheet");
    var customerData = excelLib.ReadDataFrame<Customer>("Customers");

Error Handling

ExcelLib includes basic error handling capabilities, throwing exceptions when critical operations fail (such as file not found or sheet not existing).

Contributing

Contributions to enhance ExcelLib, add features, or improve documentation are welcome. Please fork the repository and submit a pull request with your changes.

License

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 123 9/11/2024
1.2.0 102 8/7/2024
1.1.9 110 6/18/2024
1.1.8 122 6/18/2024 1.1.8 is deprecated because it has critical bugs.
1.1.7 108 6/18/2024
1.1.6 107 5/20/2024
1.1.5 117 5/10/2024
1.1.4 81 5/2/2024
1.1.3 74 5/2/2024
1.1.2 89 5/1/2024
1.1.1 100 5/1/2024
1.1.0 101 5/1/2024
1.0.9 120 5/1/2024 1.0.9 is deprecated because it has critical bugs.
1.0.8 100 5/1/2024
1.0.7 110 4/30/2024
1.0.6 109 4/30/2024
1.0.5 110 4/30/2024
1.0.4 112 4/30/2024
1.0.3 106 4/30/2024
1.0.2 108 4/30/2024
1.0.1 107 4/30/2024
1.0.0 104 4/29/2024