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" />
<PackageReference Include="HTL.Aspose.MergeTemplate" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=HTL.Aspose.MergeTemplate&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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:
tableName→resultIndex(string)→List<MergeColumnDynamicInfo>
Trong đó mỗi MergeColumnDynamicInfo mô tả 1 cột được sinh:
GroupIndex: phải bằngDynamicColumnRule.Idđể rule biết cột nào thuộc anchor nàoText: tiêu đề cộtFieldName: 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ùngParentNameWidth: độ rộng cộtDataType: 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 | Versions 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.
-
net8.0
- Aspose.Cells (>= 21.10.0)
- Aspose.Words (>= 21.6.0)
- HTL.Infrastructure.Storage (>= 1.0.7)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- PDFsharp (>= 6.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.