GenericClosedXMLHelper 1.0.0
dotnet add package GenericClosedXMLHelper --version 1.0.0
NuGet\Install-Package GenericClosedXMLHelper -Version 1.0.0
<PackageReference Include="GenericClosedXMLHelper" Version="1.0.0" />
<PackageVersion Include="GenericClosedXMLHelper" Version="1.0.0" />
<PackageReference Include="GenericClosedXMLHelper" />
paket add GenericClosedXMLHelper --version 1.0.0
#r "nuget: GenericClosedXMLHelper, 1.0.0"
#:package GenericClosedXMLHelper@1.0.0
#addin nuget:?package=GenericClosedXMLHelper&version=1.0.0
#tool nuget:?package=GenericClosedXMLHelper&version=1.0.0
Overview ExcelHelper is a utility class that allows you to generate Excel files using the ClosedXML library. It enables creating structured Excel files from multiple data models, with customization options like custom column widths, header styles, data formats, and more.
This package makes it easy to export complex data models into Excel worksheets with flexibility for customization.
Features Dynamic Sheet Generation: Create multiple sheets based on data.
Customizable Header Styling: Bold headers, background colors, and text alignment.
Data Formatting: Apply custom formats for numbers and dates.
Row Styling: Alternate row colors for better readability.
Column Widths: Auto-fit or define custom column widths.
Freezing Top Row: Optionally freeze the top row for easy navigation in large datasets.
Installation To use the ExcelHelper class, you need to install the ClosedXML library. You can do so via NuGet:
bash Copy dotnet add package ClosedXML Usage Example Here's a sample usage of the GenerateExcel method:
csharp Copy using System; using System.Collections.Generic;
class Program { static void Main() { // Example data var data = new Dictionary<string, (Type ModelType, List<object> Data)> { { "Sheet1", ( typeof(YourDataModel), new List<object> { new YourDataModel { Property1 = "Value1", Property2 = 100 }, new YourDataModel { Property1 = "Value2", Property2 = 200 } } ) } };
var config = new ExcelFormattingConfig
{
BoldHeader = true,
HeaderBackgroundColor = XLColor.LightGray,
TextAlignment = XLAlignmentHorizontalValues.Center,
VerticalAlignment = XLAlignmentVerticalValues.Center,
AlternateRowColor = XLColor.LightYellow,
AutoFitColumns = true,
DefaultRowHeight = 20,
FreezeTopRow = true
};
ExcelHelper.GenerateExcel(data, "output.xlsx", config);
Console.WriteLine("Excel file generated successfully!");
}
} Parameters data: A dictionary containing the sheet name as the key, and a tuple containing the ModelType and the list of data objects. Each object will be written as a row in the corresponding sheet.
filePath: The file path where the generated Excel file will be saved.
config: An instance of ExcelFormattingConfig that holds all the customizable settings for the Excel file's appearance and behavior.
ExcelFormattingConfig The configuration object allows the following customization:
BoldHeader: Set to true to make headers bold.
HeaderBackgroundColor: Define the background color for the headers.
TextAlignment: Set the horizontal alignment for the text in the cells.
VerticalAlignment: Set the vertical alignment for the text in the cells.
AlternateRowColor: Set an alternate row color for better readability (optional).
AutoFitColumns: Set to true to auto-fit columns based on their content.
CustomColumnWidths: A dictionary for custom column widths.
DefaultRowHeight: Set the default row height for the worksheet.
FreezeTopRow: Set to true to freeze the top row in the worksheet.
Excel Attribute The ExcelAttribute can be used to annotate properties in your data models to specify their appearance in the Excel sheet.
Example Model csharp Copy public class YourDataModel { [Excel(SheetName = "Sheet1", DisplayName = "Property 1", Order = 1)] public string Property1 { get; set; }
[Excel(SheetName = "Sheet1", DisplayName = "Property 2", Order = 2)]
public int Property2 { get; set; }
} SheetName: The name of the sheet this property belongs to.
DisplayName: The name of the column header.
Order: The order of the columns in the Excel sheet.
IsHidden: Set to true to hide the column.
Format: Set a custom format for the column (e.g., "mm/dd/yyyy" for dates).
License This project is licensed under the MIT License - see the LICENSE file for details.
Contributing Feel free to fork the repository, submit issues, and open pull requests to improve the functionality and features of ExcelHelper.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- ClosedXML (>= 0.104.2)
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.0.0 | 184 | 4/4/2025 |