{"id":26364928,"url":"https://github.com/jjosh102/excel-transform-load","last_synced_at":"2025-03-16T19:28:45.488Z","repository":{"id":279031131,"uuid":"937505892","full_name":"jjosh102/excel-transform-load","owner":"jjosh102","description":"ExcelTransformLoad is a simple .NET library for extracting data from Excel files using ClosedXML, transforming it as needed, and loading it into your object.","archived":false,"fork":false,"pushed_at":"2025-03-12T01:07:15.000Z","size":756,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T02:21:38.756Z","etag":null,"topics":["csharp","excel","show"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jjosh102.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-23T08:10:22.000Z","updated_at":"2025-03-12T01:07:18.000Z","dependencies_parsed_at":"2025-02-23T10:25:23.877Z","dependency_job_id":"07cf6574-f92c-474d-b53e-daae90cc9bdd","html_url":"https://github.com/jjosh102/excel-transform-load","commit_stats":null,"previous_names":["jjosh102/excel-transform-load"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fexcel-transform-load","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fexcel-transform-load/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fexcel-transform-load/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fexcel-transform-load/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jjosh102","download_url":"https://codeload.github.com/jjosh102/excel-transform-load/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243919294,"owners_count":20368864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","excel","show"],"created_at":"2025-03-16T19:28:44.835Z","updated_at":"2025-03-16T19:28:45.480Z","avatar_url":"https://github.com/jjosh102.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExcelTransformLoad\n\n## Overview\nExcelTransformLoad is a robust .NET library for extracting data from Excel files using [ClosedXML](https://github.com/ClosedXML/ClosedXML), transforming it as needed, and loading it into your objects with minimal effort. It supports a variety of data types, flexible column mapping, and both attribute-based and manual mapping approaches.\n\n## Getting Started\n\n### Installation (Coming soon)\n\n\n### Basic Usage\n\n#### 1. Define your model with ExcelColumn attributes\n```csharp\npublic class Person {\n    [ExcelColumn(\"Full Name\", \"Name\", \"Employee Name\")]\n    public string? Name { get; set; }\n    \n    [ExcelColumn(\"Age\", \"Employee Age\")]\n    public int? Age { get; set; }\n    \n    [ExcelColumn(\"Salary\")]\n    public decimal? Salary { get; set; }\n    \n    [ExcelColumn(\"Join Date\")]\n    public DateTime JoinDate { get; set; }\n    \n    [ExcelColumn(\"Last Active\", \"Last Activity\")]\n    public DateTime? LastActive { get; set; }\n}\n```\n\nThe `ExcelColumn` attribute maps Excel column headers to C# properties. You can provide multiple possible column names to handle variations in your Excel files gracefully.\n\n#### 2. Extract data from Excel\n\n##### From a Stream\n```csharp\n// Get a stream from a file, memory, or any other source\nusing var stream = File.OpenRead(\"employees.xlsx\");\n\n// Extract the data using a fluent API\nvar people = new ExcelExtractor()\n    .WithHeader(true)               // Excel file contains headers\n    .WithWorksheetIndex(1)          // Use the first worksheet (1-based index)\n    .FromStream(stream)             // Set the source stream\n    .Extract\u003cPerson\u003e();             // Perform the extraction\n\n// Use the extracted data\nforeach (var person in people) {\n    Console.WriteLine($\"Name: {person.Name}, Age: {person.Age}, Joined: {person.JoinDate:d}\");\n}\n```\n\n##### From a File\n```csharp\nvar people = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromFile(\"employees.xlsx\")\n    .Extract\u003cPerson\u003e();\n```\n\n## Advanced Features\n\n### Working with Files Without Headers\nFor Excel files without headers, you can use column position for extraction:\n\n```csharp\npublic class PersonNoHeader {\n    // No attributes needed - properties are mapped by column position (1-based)\n    // First column (A) maps to first property, second column (B) to second property, etc.\n    public string? Name { get; set; }\n    public int? Age { get; set; }\n    public decimal? Salary { get; set; }\n    public DateTime JoinDate { get; set; }\n    public DateTime? LastActive { get; set; }\n}\n\n// Extract the data\nvar people = new ExcelExtractor()\n    .WithHeader(false)              // Specify that there's no header row\n    .WithWorksheetIndex(1)\n    .FromFile(\"employees-no-header.xlsx\")\n    .Extract\u003cPersonNoHeader\u003e();\n```\n\n### Manual Mapping\nFor more control over the extraction process, you can use manual mapping:\n\n```csharp\n// Extract data with manual mapping\nvar people = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromStream(stream)\n    .ExtractWithManualMapping(row =\u003e new Person {\n        Name = row.Cell(1).GetString(),\n        Age = !row.Cell(2).IsEmpty() ? (int)row.Cell(2).GetDouble() : null,\n        Salary = !row.Cell(3).IsEmpty() ? (decimal)row.Cell(3).GetDouble() : null,\n        JoinDate = row.Cell(4).GetDateTime(),\n        LastActive = !row.Cell(5).IsEmpty() ? row.Cell(5).GetDateTime() : null\n    });\n```\n\n### Supported Data Types\n\nExcelTransformLoad supports a wide range of data types:\n\n- Basic types: `string`, `int`, `decimal`, `double`, `DateTime`\n- Nullable variants: `int?`, `decimal?`, `DateTime?`, etc.\n- `TimeSpan` for time values\n- `Guid` for unique identifiers\n- Enums for categorized data\n\n### Selecting Specific Columns\n\nIf you only need certain columns from an Excel file:\n\n```csharp\npublic class PersonWithSpecificColumns {\n    [ExcelColumn(\"Name\")]\n    public string? NameOnly { get; set; }\n    \n    [ExcelColumn(\"Salary\")]\n    public decimal SalaryOnly { get; set; }\n}\n\nvar partialData = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromFile(\"employees.xlsx\")\n    .Extract\u003cPersonWithSpecificColumns\u003e();\n```\n\n### Handling Enums\n\nEnums are supported out of the box:\n\n```csharp\npublic enum UserStatus {\n    None,\n    Active,\n    Inactive,\n    Suspended\n}\n\npublic class PersonWithEnumStatus {\n    [ExcelColumn(\"Name\")]\n    public string? Name { get; set; }\n    \n    [ExcelColumn(\"Status\")]\n    public UserStatus Status { get; set; }\n}\n\nvar people = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromFile(\"employees.xlsx\")\n    .Extract\u003cPersonWithEnumStatus\u003e();\n```\n\n### Data Transformation During Extraction\n\nTransform data as it's being extracted:\n\n```csharp\nvar transformedData = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromStream(stream)\n    .ExtractWithManualMapping(row =\u003e new Person {\n        // Convert names to uppercase\n        Name = row.Cell(1).GetString().ToUpper(),\n        // Double the age values\n        Age = !row.Cell(2).IsEmpty() ? (int)(row.Cell(2).GetDouble() * 2) : null,\n        // Halve the salary values\n        Salary = !row.Cell(3).IsEmpty() ? (decimal)(row.Cell(3).GetDouble() / 2) : null,\n        // Add a year to join dates\n        JoinDate = row.Cell(4).GetDateTime().AddYears(1),\n        // Use current date for missing activity dates\n        LastActive = !row.Cell(5).IsEmpty() ? row.Cell(5).GetDateTime() : DateTime.Now\n    });\n```\n\n### Converting to Different Target Types\n\nYou can map Excel data to any object type:\n\n```csharp\npublic class CustomPerson {\n    public string? FullName { get; set; }\n    public int YearsOld { get; set; }\n    public decimal AnnualSalary { get; set; }\n    public DateTime StartDate { get; set; }\n    public bool IsActive { get; set; }\n}\n\nvar customData = new ExcelExtractor()\n    .WithHeader(true)\n    .WithWorksheetIndex(1)\n    .FromStream(stream)\n    .ExtractWithManualMapping(row =\u003e new CustomPerson {\n        FullName = row.Cell(1).GetString(),\n        YearsOld = !row.Cell(2).IsEmpty() ? (int)row.Cell(2).GetDouble() : 0,\n        AnnualSalary = !row.Cell(3).IsEmpty() ? (decimal)row.Cell(3).GetDouble() : 0,\n        StartDate = row.Cell(4).GetDateTime(),\n        IsActive = !row.Cell(5).IsEmpty()\n    });\n```\n\n## Performance Considerations\n\nBased on benchmarks, both attribute-based and manual mapping provide good performance:\n\n| Method                               | Mean       | Error     | StdDev    | Gen0      | Gen1      | Gen2      | Allocated |\n|------------------------------------- |-----------:|----------:|----------:|----------:|----------:|----------:|----------:|\n| SmallFile_AttributeMapping           |   3.330 ms | 0.0482 ms | 0.0403 ms |  140.6250 |   46.8750 |         - |   1.89 MB |\n| SmallFile_ManualMapping              |   2.740 ms | 0.0197 ms | 0.0154 ms |  148.4375 |   46.8750 |         - |   1.86 MB |\n| SmallFile_ManualMapping_NoAttributes |   2.766 ms | 0.0550 ms | 0.0540 ms |  148.4375 |   46.8750 |         - |   1.86 MB |\n| MediumFile_AttributeMapping          |  16.327 ms | 0.3255 ms | 0.5615 ms | 1000.0000 |  727.2727 |   90.9091 |  13.66 MB |\n| MediumFile_ManualMapping             |  15.806 ms | 0.3136 ms | 0.5492 ms | 1000.0000 |  700.0000 |  100.0000 |  13.67 MB |\n| LargeFile_AttributeMapping           | 177.912 ms | 3.4578 ms | 4.8473 ms | 9000.0000 | 4000.0000 | 2000.0000 | 129.31 MB |\n| LargeFile_ManualMapping              | 183.702 ms | 3.1083 ms | 2.7555 ms | 9000.0000 | 5000.0000 | 2000.0000 | 129.61 MB |\n| ManyColumns_AttributeMapping         |  27.877 ms | 0.5434 ms | 0.5815 ms | 1444.4444 |  888.8889 |  222.2222 |  18.74 MB |\n| ManyColumns_ManualMapping            |  27.434 ms | 0.4533 ms | 0.4241 ms | 1444.4444 |  888.8889 |  222.2222 |  18.69 MB |\n\nManual mapping provides a slight performance edge for small files, while both approaches perform similarly for larger datasets.\n\n## Why Use ExcelTransformLoad?\nIf you're already using [ClosedXML](https://github.com/ClosedXML/ClosedXML) or similar libraries extensively, this one might not add much extra value. But if you're looking for a simple way to read an Excel file and load it into your objects without any hassle, this library is worth checking out!\n\nIt's user-friendly and follows a fluent pattern, making it easy to define your options in a natural, intuitive way.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjosh102%2Fexcel-transform-load","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjjosh102%2Fexcel-transform-load","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjosh102%2Fexcel-transform-load/lists"}