Using SuperConvert.Abstraction NuGet Library for Data Conversion

Introduction

SuperConvert.Abstraction is a powerful NuGet library that provides seamless data conversion capabilities for your C# web applications. With the introduction of the SuperConvertExcelService, you can easily convert data between various formats such as CSV, JSON, and XLS. In this article, we'll guide you through the process of integrating and using this service in your application.

Nuget Package

Installation

To get started, follow these steps to install the SuperConvert.Abstraction NuGet package in your project.

  1. NuGet Package Manager Console: Run the following command in the NuGet Package Manager Console.
    Install-Package SuperConvert.Abstraction -Version 1.0.0

2. Package Manager UI: Open the Package Manager UI, search for “SuperConvert.Abstraction,” and click “Install.”

Configuring Dependency Injection

Once the SuperConvert.Abstraction package is installed, and you can easily configure the SuperConvertExcelService for dependency injection in your application.

Startup.cs: Open your Startup.cs file and add the following code inside the ConfigureServices method.

using SuperConvert.Abstraction.Extensions;

// ...

public void ConfigureServices(IServiceCollection services)
{
    // ...
    services.UseSuperConvertExcelService();
    // ...
}

Using SuperConvertExcelService

With the SuperConvertExcelService registered in the dependency injection container, you can now use its methods for data conversion.

Example. Convert DataTable to CSV

using SuperConvert.Abstraction;
using Microsoft.AspNetCore.Mvc;
using System.Data;

namespace YourNamespace.Controllers
{
    public class SuperConvertController : Controller
    {
        private readonly ISuperConvertExcelService _excelService;

        public SuperConvertController(ISuperConvertExcelService excelService)
        {
            _excelService = excelService;
        }

        public IActionResult ConvertDataTableToCsv()
        {
            DataTable dataTable = CreateSampleDataTable(); // Replace with your data source

            // Convert DataTable to CSV and save to a file
            string path = "path_to_save_csv";
            string fileName = "data";
            _excelService.DataTableToCsv(dataTable, path, fileName);

            return View();
        }

        // Other methods for different conversions
    }
}

Using SuperConvertExcelService Methods

The methods provided by SuperConvertExcelService allow you to perform various data conversion tasks, including converting JSON to CSV, CSV to DataTable, JSON to XLS, and more.

Conclusion

By utilizing the SuperConvert.Abstraction library and the SuperConvertExcelService, you can easily integrate powerful data conversion capabilities into your web applications. The seamless integration and easy-to-use methods make handling data conversion tasks a breeze.

Stay tuned for future updates and enhancements as SuperConvert.Abstraction continues to evolve to meet your data conversion needs.

For more information, refer to the SuperConvert Documentation and start simplifying your data conversion tasks today! πŸ’»πŸ”§πŸ“Š


Recommended Free Ebook
Similar Articles