d72b583319
[XP.ReportEngine] 模型与配置扩展:ReportOutputFormat 枚举:新增 Excel=1, Csv=2, Txt=3(显式序号,向后兼容);新增多格式相关配置加载。
47 lines
2.2 KiB
C#
47 lines
2.2 KiB
C#
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}");
|
||
}
|
||
}
|
||
}
|
||
}
|