Advanced Export Techniques with Magicodes.IE

Magicodes.IE is a universal import/export library that supports DTO-based operations for Excel, Word, PDF, CSV, and HTML formats. This tutorial demonstrates how to leverage Magicodes.IE for sophisticated export scenarios that meet demandign client requirements. Splitting a Single Data Source Across Multiple Sheets

When dealing with large datasets, clients often prefer data to be split across separate worksheets for better manageability. Implementing this is straightforward with IE. First, define your DTO: ``` [ExcelExporter(Name = "ExportData", TableStyle = "None", AutoFitAllColumn = true, MaxRowNumberOnASheet = 100)] public class SalesRecord { [ExporterHeader(DisplayName = "Bold Header", IsBold = true)] public string Product { get; set; }

[ExporterHeader(DisplayName = "Standard Text")]
public string Description { get; set; }

[ExporterHeader(DisplayName = "Hidden Field", IsIgnore = true)]
public string InternalCode { get; set; }

[ExporterHeader(DisplayName = "Amount", Format = "#,##0")]
public decimal Amount { get; set; }

[ExporterHeader(DisplayName = "Category", IsAutoFit = true)]
public string Category { get; set; }

[ExporterHeader(DisplayName = "Start Date", Format = "yyyy-MM-dd")]
public DateTime StartDate { get; set; }

[ExporterHeader(DisplayName = "End Date", Format = "yyyy-MM-dd HH:mm:ss")]
public DateTime? EndDate { get; set; }

public DateTime CreatedAt { get; set; }

public DateTime UpdatedAt { get; set; }

}


The **MaxRowNumberOnASheet** attribute controls the maximum rows per worksheet. Standard export logic hendles the sheet splitting automatically: ```
var result = await exporter.Export(filePath,
    GenFu.GenFu.ListOf<SalesRecord>(300));

This approach handles large datasets efficiently with minimal configuraton. Exporting Multiple Data Sources to Separate Sheets

Clients sometimes request combining different datasets into a unified export. Magicodes.IE handles this scenario elegantly. DTO Definition for Primary Dataset:``` [ExcelExporter(Name = "PrimaryData", TableStyle = "Light10", AutoFitAllColumn = true, AutoFitMaxRows = 5000)] public class PrimaryDataset { [ExporterHeader(DisplayName = "Bold Header", IsBold = true)] public string Product { get; set; }

[ExporterHeader(DisplayName = "Description")]
public string Description { get; set; }

[ExporterHeader(DisplayName = "Internal", IsIgnore = true)]
public string InternalCode { get; set; }

[ExporterHeader(DisplayName = "Amount", Format = "#,##0")]
public decimal Amount { get; set; }

[ExporterHeader(DisplayName = "Category", IsAutoFit = true)]
public string Category { get; set; }

[ExporterHeader(DisplayName = "Start Date", Format = "yyyy-MM-dd")]
public DateTime StartDate { get; set; }

[ExporterHeader(DisplayName = "End Date", Format = "yyyy-MM-dd HH:mm:ss")]
public DateTime? EndDate { get; set; }

[ExporterHeader(Width = 100)]
public DateTime CreatedAt { get; set; }

public DateTime UpdatedAt { get; set; }

[ExporterHeader(DisplayName = "Reference Number", Format = "#,##0")]
public long ReferenceNumber { get; set; }

}


**DTO Definition for Secondary Dataset:**```
[ExcelExporter(Name = "SecondaryData", TableStyle = "None", AutoFitAllColumn = true, MaxRowNumberOnASheet = 100)]
public class SecondaryDataset
{
    [ExporterHeader(DisplayName = "Bold Header", IsBold = true)]
    public string Product { get; set; }

    [ExporterHeader(DisplayName = "Description")]
    public string Description { get; set; }

    [ExporterHeader(DisplayName = "Internal", IsIgnore = true)]
    public string InternalCode { get; set; }

    [ExporterHeader(DisplayName = "Amount", Format = "#,##0")]
    public decimal Amount { get; set; }

    [ExporterHeader(DisplayName = "Category", IsAutoFit = true)]
    public string Category { get; set; }

    [ExporterHeader(DisplayName = "Start Date", Format = "yyyy-MM-dd")]
    public DateTime StartDate { get; set; }

    [ExporterHeader(DisplayName = "End Date", Format = "yyyy-MM-dd HH:mm:ss")]
    public DateTime? EndDate { get; set; }

    public DateTime CreatedAt { get; set; }

    public DateTime UpdatedAt { get; set; }
}

After defining multiple DTOs, use the flexible API to combine exports: ``` var datasetA = GenFu.GenFu.ListOf<PrimaryDataset>(); var datasetB = GenFu.GenFu.ListOf<SecondaryDataset>(30); var result = await exporter .Append(datasetA) .SeparateByColumn().Append(datasetB) .SeparateByColumn().Append(datasetB) .ExportAppendData(filePath);


The **Append** method adds data sources while **SeparateByColumn** inserts column breaks between datasets. Each DTO maintains its configured styling, ensuring consistent formatting throughout the export. Splitting Multiple Data Sources by Sheet
----------------------------------------

For cleaner organization, data can be distributed across separate worksheets using the **SeparateBySheet** method: ```
var result = exporter
    .Append(datasetA, "MainSheet")
    .SeparateBySheet()
    .Append(datasetB)
    .ExportAppendData(filePath);

The Append method accepts an optional sheet name parameter, allowing dynamic naming for each worksheet. Splitting Multiple Data Sources by Row

When clients require datasets to be concatenated row-by-row within the same sheet, use the SeparateByRow method: ``` var result = await exporter .Append(datasetA) .SeparateByRow() .Append(datasetB) .ExportAppendData(filePath);


This approach positions data consecutively without intermediate breaks, suitable for continuous reporting. Adding Dynamic Headers
----------------------

For scenarios requiring headers to appear after row splits, the **AppendHeaders** method provides the solution: ```
var result = await exporter
    .Append(datasetA)
    .SeparateByRow()
    .AppendHeaders()
    .Append(datasetB)
    .ExportAppendData(filePath);

This ensures headers remain visible and properly positioned throughout the exported document. API Reference Summary

API Method Description
Append Adds a data source; supports optional sheet name parameter
AppendHeaders Inserts headers at the current position
SeparateByColumn Inserts column break between data sections
SeparateBySheet Creates new worksheet for subsequent data
SeparateByRow Appends data in continuous rows without breaks
ExportAppendData Executes the chained export operation

Tags: Magicodes.IE C# Excel Export Import Export Library .NET

Posted on Sun, 06 Sep 2026 16:15:42 +0000 by SeanWoods