Files
XplorePlane/XP.ReportEngine/Services/ReportFormatExtensions.cs
T
QI Mingxuan d72b583319 [XP.ReportEngine] 新增 TXT/CSV/Excel 三种报告输出格式支持;Excel (.xlsx) 报告生成器,基于 ClosedXML,支持结构化生成和模板填充两种模式; 新增 XplorePlane_ReportTemplate.xlsx:Excel 报告模板文件。
[XP.ReportEngine] 模型与配置扩展:ReportOutputFormat 枚举:新增 Excel=1, Csv=2, Txt=3(显式序号,向后兼容);新增多格式相关配置加载。
2026-07-01 11:31:41 +08:00

47 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using XP.ReportEngine.Models;
namespace XP.ReportEngine.Services
{
/// <summary>
/// 报告输出格式辅助方法 | Report output format helper methods
/// 提供格式 → 文件扩展名的映射,供报告服务(ReportService)在解析输出文件路径时使用。
/// Provides format → file extension mapping, used by ReportService when resolving output file paths.
/// </summary>
internal static class ReportFormatExtensions
{
/// <summary>
/// 根据报告输出格式返回对应的文件扩展名(含点号)| Return the file extension (with dot) for the given report output format
/// 映射规则 | Mapping rules
/// Pdf → ".pdf"
/// Txt → ".txt"
/// Csv → ".csv"
/// Excel → ".xlsx"
/// </summary>
/// <param name="format">报告输出格式 | Report output format</param>
/// <returns>对应的文件扩展名(含点号,如 ".txt"| Corresponding file extension (with dot, e.g. ".txt")</returns>
/// <exception cref="NotSupportedException">
/// 当传入的格式不属于任何已定义的映射时抛出,异常消息包含该传入值。
/// Thrown when the given format does not map to any defined extension; the exception message contains the passed value.
/// </exception>
public static string GetExtension(ReportOutputFormat format)
{
switch (format)
{
case ReportOutputFormat.Pdf:
return ".pdf";
case ReportOutputFormat.Txt:
return ".txt";
case ReportOutputFormat.Csv:
return ".csv";
case ReportOutputFormat.Excel:
return ".xlsx";
default:
// 未定义的格式(含越界整数强转枚举值)| Undefined format (including out-of-range integers cast to enum)
throw new NotSupportedException(
$"不支持的报告输出格式,无法映射文件扩展名: {format} | Unsupported report output format, cannot map file extension: {format}");
}
}
}
}