Overview
Description
Surya.Ab.Export is a library designed to empower developers with seamless data export capabilities from C# objects. Whether you need to export data to Excel, CSV, Text or Pdf formats, this library provides a reliable and efficient solution by simplifying the export process and offering a range of customization options.
Installation
- .NET CLI
- Package Reference
- Linux Users
dotnet add package Surya.Ab.Export --version 6.2.61
<ItemGroup>
<PackageReference Include="Surya.Ab.Export" Version="6.2.61" />
</ItemGroup>
info
Surya.Ab.Export uses SegoeUI as it's default font. Export in PDF format is dependent on the Operating System for its font. Since, SegoeUI font is not available on Linux by default, it's required to install the font manually.
Steps to install the font on Linux :-
Step 1 : Download the font
Step 2 : RightClick and Unzip the content to Downloads folder
Step 3 : Open the termial and run the following command
sudo cp -r /Downloads/SegoeUI /usr/share/fonts/truetype/
Step 4 : Done! Now check /usr/share/fonts/truetype/ for SegoeUI folder.
Getting Started
public class Program
{
public static void Main()
{
IServiceCollection services = new ServiceCollection();
services.AddAbExport();
var serviceProvider = services.BuildServiceProvider();
var exportManager = serviceProvider.GetRequiredService<IExporter>();
// Get data
var data = GetData();
// Get metadata - it's optional
var metadata = GetMetadata();
/* ------------ Configure ExportOption ----------------
* NOTE : All properties of ExportOption are optional.
* One can pass an empty instance of Options.
*
* EXP: var option = SingleDataSetOptions();
*/
var exportOption = new SingleDataSetOptions() { Metadata = metadata, };
// set Output format - Excel/Pdf/Csv/Tsv
var exportType = ExportType.Excel;
/* Call Export method by passing ExportType, Data and ExportOption */
Stream stream = exportManager.Export(exportType, data, exportOption);
// Path where file to be saved
string filePath = @"..\Accounts.xlsx";
// Save stream as file
using (FileStream outputFileStream = new(filePath, FileMode.Create))
{
stream.CopyTo(outputFileStream);
}
}
// SAMPLE DATA MODEL
internal class Account
{
public string? Name { get; set; }
public double AccountBalance { get; set; }
}
// Get SAMPLE DATA MODEL Instances
internal static List<Account> GetData()
{
List<Account> data =
new()
{
new Account { Name = "Deposit", AccountBalance = 1540.4574761 },
new Account { Name = "Current", AccountBalance = 10012 },
new Account { Name = "Borrowing", AccountBalance = 100 },
new Account { Name = "Other", AccountBalance = 100 },
};
return data;
}
// Get Metadata list
internal static List<PropertyMetadata> GetMetadata()
{
List<PropertyMetadata> metadata =
new()
{
new PropertyMetadata()
{
Code = "Name",
DisplayName = "Name",
DisplayOrder = 1,
DataType = DataType.String,
DisplayType = DisplayType.XXXL
},
new PropertyMetadata()
{
Code = "AccountBalance",
DisplayName = "Balance",
DisplayOrder = 2,
DataType = DataType.Number,
DisplayType = DisplayType.Amount
},
};
return metadata;
}
}