AtlasX Web Service รองรับการสร้างและ export รายงานในรูปแบบต่างๆ ผ่าน Telerik Reporting โดยใช้ ReportService ซึ่งรองรับทั้งการ export รายงานเดี่ยวและการรวมหลายรายงานเป็น report book
การตั้งค่า
กำหนดค่า Telerik Reporting ใน appsettings.json
{
"telerikReporting": {
"extensions": [
{
"name": "IMAGE",
"parameters": [
{ "Name": "OutputFormat", "Value": "JPEG" },
{ "Name": "DpiX", "Value": "300" },
{ "Name": "DpiY", "Value": "300" },
{ "Name": "TextRenderingHint", "Value": "AntiAliasGridFit" }
]
}
],
"privateFonts": [
{
"fontFamily": "TH Sarabun New",
"path": "Report/Assets/fonts/THSarabunNew/THSarabunNew.ttf"
},
{
"fontFamily": "TH Sarabun New",
"path": "Report/Assets/fonts/THSarabunNew/THSarabunNew Italic.ttf",
"fontStyle": "Italic"
},
{
"fontFamily": "TH Sarabun New",
"path": "Report/Assets/fonts/THSarabunNew/THSarabunNew Bold.ttf",
"fontStyle": "Bold"
},
{
"fontFamily": "TH Sarabun New",
"path": "Report/Assets/fonts/THSarabunNew/THSarabunNew BoldItalic.ttf",
"fontStyle": "Bold,Italic"
}
]
}
}| Section | Description |
extensions | กำหนดค่าการ export ในแต่ละรูปแบบ เช่น IMAGE กำหนด output format, DPI และ text rendering |
privateFonts | ลงทะเบียน font ที่ใช้ในรายงาน ระบุ fontFamily, path และ fontStyle (Regular, Italic, Bold, Bold Italic) |
Service Registration
ลงทะเบียน TelerikReport เข้า DI container ใน Program.cs
builder.Services.AddTelerikReporting(builder.Configuration);การใช้งาน
Inject ReportService
public class MyService
{
private readonly ReportService _reportService;
public MyService(ReportService reportService)
{
_reportService = reportService;
}
}Method
| Method | Return | Description |
ExportAsync() | RenderingResult | Export รายงานเดี่ยวจาก template ที่ระบุ |
ExportSourceBookAsync() | RenderingResult | รวมหลายรายงานเป็นไฟล์เดียวแล้ว export |
RenderingResult
| Property | Type | Description |
DocumentBytes | byte[] | เนื้อหาของไฟล์รายงาน |
MimeType | string | MIME type เช่น application/pdf |
Extension | string | นามสกุลไฟล์ เช่น pdf, xlsx |
Export Report
ใช้ ExportAsync() ในการ Export รายงานจาก template ที่กำหนด โดยส่ง REPORT_CONFIG เป็น JSON เพื่อระบุ template และรูปแบบไฟล์ที่ต้องการ
var reportConfig = new
{
template_name = "monthly-report.trdp",
export_extension = "PDF"
};
var queryParameter = new QueryParameter();
queryParameter["REPORT_CONFIG"] = JsonSerializer.Serialize(reportConfig);
queryParameter["REPORT_PARAMS"] = JsonSerializer.Serialize(new Dictionary<string, object>
{
{ "MONTH", "01" },
{ "YEAR", "2025" }
});
var result = _reportService.ExportAsync(queryParameter);| Parameter | Description |
REPORT_CONFIG | JSON ที่ระบุ template_name (ชื่อไฟล์ template) และ export_extension (รูปแบบ export เช่น PDF, XLSX, IMAGE) |
REPORT_PARAMS | JSON ที่ระบุ parameters ที่จะส่งเข้า template รายงาน (optional) |
Export Report Book
ใช้ ExportSourceBookAsync() ในการ Export หลายรายงานรวมเป็นไฟล์เดียว โดยส่ง ReportBookConfig ที่มีรายการ template และ parameters ของแต่ละรายงาน
var reportBookConfig = new ReportBookConfig
{
ExportExtension = "PDF",
ReportSources =
[
new ReportSourceConfig
{
TemplateName = "report-part1.trdp",
Params = new Dictionary<string, object>
{
{ "MONTH", "01" }
}
},
new ReportSourceConfig
{
TemplateName = "report-part2.trdp",
Params = new Dictionary<string, object>
{
{ "YEAR", "2025" }
}
}
]
};
var result = _reportService.ExportSourceBookAsync(reportBookConfig);