HTL.Aspose.MergeTemplate 1.0.1

dotnet add package HTL.Aspose.MergeTemplate --version 1.0.1
                    
NuGet\Install-Package HTL.Aspose.MergeTemplate -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HTL.Aspose.MergeTemplate" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HTL.Aspose.MergeTemplate" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="HTL.Aspose.MergeTemplate" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HTL.Aspose.MergeTemplate --version 1.0.1
                    
#r "nuget: HTL.Aspose.MergeTemplate, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HTL.Aspose.MergeTemplate@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HTL.Aspose.MergeTemplate&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=HTL.Aspose.MergeTemplate&version=1.0.1
                    
Install as a Cake Tool

Aspose.MergeTemplate

Thư viện trộn dữ liệu vào mẫu Excel có sẵn (lưu trên MinIO thông qua IStorageService) và xuất ra Excel/PDF bằng Aspose.

Đăng ký DI

services.AddAsposeMergeTemplate(configuration);

AppSettings ví dụ:

{
  "AsposeMergeTemplate": {
    "TemplateStorageType": 2,
    "OutputStorageType": 0,
    "TemplatePrefix": ""
  }
}

Cách dùng

var svc = serviceProvider.GetRequiredService<IMergeTemplateService>();

var result = await svc.MergeAsync(new MergeTemplateRequest
{
    AppCode = "System",
    CompanyCode = tenantCode,
    TemplateName = "mau-in/phieu-thu.xlsx",
    Data = mergeData, // MergeTemplateData (contracts thuần), không phụ thuộc HTL.Domain.Core
    ExportExcel = true,
    ExportPdf = true,

    // (Tuỳ chọn) custom xử lý cell cho riêng request này
    // CellValueHandle = new MyCustomCellValueHandle()
});

// result.OutputExcelPath / result.OutputPdfPath là tên file đã được lưu trên storage output (thường là Temp)

Hướng dẫn merge cột động (Dynamic Columns)

1) Quy ước trong file Excel template

  • Ô neo (anchor cell): đặt 1 ô chứa placeholder theo dạng:
    • ##{tableName}.{key}##
    • Ví dụ: ##ChiTiet.SoLuong##
  • Thư viện sẽ dùng ô neo này để xác định vị trí bắt đầu sinh cột động.
  • Nếu template của bạn có header 2 tầng (group header):
    • Tầng group nằm ở hàng trên của ô neo (rowIndex - 1)
    • Tầng tên cột nằm ở đúng hàng của ô neo (rowIndex)
    • Dòng template để binding detail nằm ở hàng dưới (rowIndex + 1) và sẽ được set thành ##{tableName}.{FieldName}##

2) Khai báo rule sinh cột động (Metadata.DynamicColumnRules)

Bạn khai báo các rule để “bật” cột động tại các anchor key trong template:

mergeData.Metadata.DynamicColumnRules.Add(new MergeDynamicColumnRule
{
    Id = 1,
    TableName = "ChiTiet",
    Key = "SoLuong",       // khớp với ##ChiTiet.SoLuong##
    IsDynamic = true,
    ResultIndex = 0        // sẽ map với ColumnInfoDetails["ChiTiet"]["0"]
});

3) Truyền danh sách cột động thực tế (ColumnInfoDetails)

MergeTemplateData.ColumnInfoDetails có cấu trúc:

  • tableNameresultIndex(string)List<MergeColumnDynamicInfo>

Trong đó mỗi MergeColumnDynamicInfo mô tả 1 cột được sinh:

  • GroupIndex: phải bằng DynamicColumnRule.Id để rule biết cột nào thuộc anchor nào
  • Text: tiêu đề cột
  • FieldName: tên field để sinh placeholder ở dòng template: ##{tableName}.{FieldName}##
  • ParentName (tuỳ chọn): nếu có sẽ tạo group header và tự merge theo nhóm cùng ParentName
  • Width: độ rộng cột
  • DataType: kiểu dữ liệu để format mặc định

Ví dụ:

mergeData.ColumnInfoDetails["ChiTiet"] = new Dictionary<string, List<MergeColumnDynamicInfo>>
{
    ["0"] = new List<MergeColumnDynamicInfo>
    {
        new()
        {
            GroupIndex = 1,
            Text = "Kỳ 1",
            FieldName = "SoLuongKy1",
            ParentName = "Số lượng",
            Width = 12,
            DataType = MergeDataType.Decimal
        },
        new()
        {
            GroupIndex = 1,
            Text = "Kỳ 2",
            FieldName = "SoLuongKy2",
            ParentName = "Số lượng",
            Width = 12,
            DataType = MergeDataType.Decimal
        }
    }
};

4) Lưu ý quan trọng

  • Nếu số cột động lớn hơn số cột đang merge trong template, thư viện sẽ Insert thêm cột và tự gán header/template.
  • Nếu anchor cell đang merge, thư viện sẽ tự unmerge/merge lại để khớp số lượng cột động.
  • Dữ liệu detail thật khi merge vẫn lấy theo Details[tableName] và placeholder ##{tableName}.{field}## ở dòng template.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 98 5/10/2026
1.0.0 122 5/7/2026