![]() |
VOOZH | about |
dotnet add package TJC.Cyclops.Reporting --version 2026.6.11.2
NuGet\Install-Package TJC.Cyclops.Reporting -Version 2026.6.11.2
<PackageReference Include="TJC.Cyclops.Reporting" Version="2026.6.11.2" />
<PackageVersion Include="TJC.Cyclops.Reporting" Version="2026.6.11.2" />Directory.Packages.props
<PackageReference Include="TJC.Cyclops.Reporting" />Project file
paket add TJC.Cyclops.Reporting --version 2026.6.11.2
#r "nuget: TJC.Cyclops.Reporting, 2026.6.11.2"
#:package TJC.Cyclops.Reporting@2026.6.11.2
#addin nuget:?package=TJC.Cyclops.Reporting&version=2026.6.11.2Install as a Cake Addin
#tool nuget:?package=TJC.Cyclops.Reporting&version=2026.6.11.2Install as a Cake Tool
Cyclops.Reporting 是 Cyclops.Framework 框架中的报表生成组件,提供两种报表模式:
List<T>,通过特性标注快速导出 CSV/Excel适用于快速、简单的数据导出场景:
List<T> 泛型数据,自动识别属性生成报表列[ReportDescription] 特性自定义列标题、排序、格式[ReportIgnore] 特性忽略不需要导出的属性适用于需要运行时配置的复杂报表场景:
db_report_config 表)db_report_column_config 表)None(原值输出)、ValueMap(JSON 值映射)、LuaScript(Lua 脚本转换)| 类别 | 函数 | 说明 |
|---|---|---|
| 🌐 HTTP | http_get, http_post, http_put, http_delete, http_patch |
RESTful API 调用,返回 JSON 字符串 |
| 📦 JSON | json_parse, json_stringify |
JSON 解析与序列化 |
| ✂️ 字符串 | string_format, string_split, string_match |
字符串格式化、分割、正则匹配 |
| 📅 日期 | date_format, date_now |
日期格式化、获取当前时间 |
| 🔐 加密 | md5, sha256, base64_encode, base64_decode |
加密与编码 |
| 🔍 正则 | regex_match, regex_replace |
正则表达式匹配与替换 |
| 📝 日志 | log_info, log_error |
日志记录 |
Install-Package TJC.Cyclops.Reporting
using Cyclops.Reporting.Extensions;
builder.Services.AddCyclopsReporting();
注册的服务:
LuaScriptEngine - Singleton(全局复用)DynamicReportService - ScopedReportConfigService - ScopedDynamicReportRepository - Scopedusing Cyclops.Reporting;
using Cyclops.Reporting.Attrs;
// 定义数据模型
public class Employee
{
[ReportDescription("员工姓名", 1)]
public string Name { get; set; }
[ReportDescription("是否在职", 2, "在职,离职")]
public bool IsActive { get; set; }
[ReportDescription("入职日期", 3, datetimeFormat: "yyyy-MM-dd")]
public DateTime HireDate { get; set; }
[ReportDescription("部门", 4)]
public string Department { get; set; }
[ReportIgnore] // 忽略此字段
public string InternalCode { get; set; }
}
// 准备数据并导出
var employees = new List<Employee>
{
new Employee { Name = "张三", IsActive = true, HireDate = DateTime.Now.AddYears(-2), Department = "技术部" },
new Employee { Name = "李四", IsActive = false, HireDate = DateTime.Now.AddYears(-1), Department = "市场部" }
};
var report = new Report<Employee>(employees);
report.Export("员工信息.xlsx"); // Excel 格式
report.Export("员工信息.csv"); // CSV 格式
using Cyclops.Reporting.Dynamic.Entities;
using Cyclops.Reporting.Dynamic.Services;
public class ReportAdminController
{
private readonly ReportConfigService _configService;
public ReportAdminController(ReportConfigService configService)
{
_configService = configService;
}
// 创建报表配置
public async Task<long> CreateReport()
{
var config = new DbReportConfig
{
Name = "用户活跃度报表",
Description = "统计用户登录和操作情况",
PreviewRows = 100,
Status = 1,
// SQL 模板:纯 SQL,支持参数化查询
SqlTemplate = @"
SELECT u.user_name, u.last_login_time, d.dept_name
FROM sys_user u
LEFT JOIN sys_dept d ON u.dept_id = d.id
WHERE 1=1
AND (@dept_id IS NULL OR u.dept_id = @dept_id)
AND (@start_time IS NULL OR u.last_login_time >= @start_time)
",
// 列转换 Lua 脚本:定义转换函数
LuaScript = @"
function FormatDateTime(value)
if value and value ~= '' then
return string.sub(value, 1, 19)
end
return '从未登录'
end
"
};
return await _configService.SaveConfigAsync(config);
}
// 配置列映射和转换
public async Task ConfigureColumns(long reportId)
{
var columns = new List<DbReportColumnConfig>
{
new DbReportColumnConfig
{
ColumnName = "user_name",
DisplayName = "用户名",
SortNo = 1,
ConverterType = "None"
},
new DbReportColumnConfig
{
ColumnName = "last_login_time",
DisplayName = "最后登录时间",
SortNo = 2,
ConverterType = "LuaScript",
ConverterConfig = "FormatDateTime(value)"
},
new DbReportColumnConfig
{
ColumnName = "dept_name",
DisplayName = "所属部门",
SortNo = 3,
ConverterType = "ValueMap",
ConverterConfig = "{\"技术部\":\"研发部\",\"市场部\":\"营销部\"}"
}
};
await _configService.SaveColumnConfigsAsync(reportId, columns);
}
}
using Cyclops.Reporting.Dynamic.Models;
using Cyclops.Reporting.Dynamic.Services;
public class ReportController
{
private readonly DynamicReportService _reportService;
public ReportController(DynamicReportService reportService)
{
_reportService = reportService;
}
// 预览报表
public async Task<IActionResult> Preview([FromBody] ReportPreviewInput input)
{
var dataTable = await _reportService.PreviewAsync(
reportConfigId: input.ReportConfigId,
sqlParams: input.SqlParameters,
previewRows: 50
);
return Ok(dataTable);
}
// 导出报表到流
public async Task<IActionResult> Export([FromBody] ReportExportInput input)
{
var stream = await _reportService.ExportAsync(
reportConfigId: input.ReportConfigId,
sqlParams: input.SqlParameters,
format: input.Format
);
var fileName = $"报表_{DateTime.Now:yyyyMMddHHmmss}.xlsx";
return File(stream, "application/octet-stream", fileName);
}
}
-- 示例1:头像转 HTML 标签
if value ~= nil and type(value) == "string" and value ~= "" then
return string_format('<img src="%s" width=25 />', {value})
end
return ""
-- 示例2:金额格式化
local amount = tonumber(value) or 0
if amount > 0 then
return string_format('%.2f 元', {amount / 100})
end
return '0.00 元'
-- 示例3:日期截取
if value and #value >= 10 then
return string.sub(value, 1, 10)
end
return value or ""
接口信息
POST https://api.example.com/user/getFullNameAuthorization: Bearer {token}{
"userId": "88888888"
}
{
"fullName": "yswenli"
}
前置条件:需通过 luaEngine.RegisterFunction 注册 auth_post(url, token, body) 自定义函数(支持 Bearer Token 认证)。
LuaScript 示例
-- 通过 userid 获取用户全名(带 Bearer Token 认证的 POST 请求)
function GetFullNameByUserId(userId)
if not userId or userId == '' then
return ''
end
-- 认证 Token(建议从配置或环境变量读取)
local token = 'your-bearer-token-here'
-- 构造 POST 请求体
local requestBody = json_stringify({
userId = userId
})
-- 发送带认证的 POST 请求
local resp = auth_post('https://api.example.com/user/getFullName', token, requestBody)
-- 解析返回结果
if resp and resp ~= '' then
local result = json_parse(resp)
if result and result.fullName then
return result.fullName
end
end
return '未知用户'
end
列配置使用:ConverterType = "LuaScript",ConverterConfig = "GetFullNameByUserId(value)"
Cyclops.Reporting/
├── Report.cs # 静态报表入口 Report<T>
├── GlobalUsing.cs # 全局 using 声明
├── Attrs/
│ ├── ReportDescriptionAttribute.cs # 列描述特性(标题、排序、格式)
│ └── ReportIgnoreAttribute.cs # 忽略导出特性
├── Core/ # 静态报表核心
│ ├── ReportBase.cs # 报表基类(属性解析、数据转换)
│ ├── ReportColumn.cs # 列信息模型
│ ├── ReportCsv.cs # CSV 导出实现
│ └── ReportExcel.cs # Excel 导出实现
├── Dynamic/ # 动态报表模块
│ ├── Entities/
│ │ ├── DbReportConfig.cs # 报表配置实体(db_report_config 表)
│ │ └── DbReportColumnConfig.cs # 列配置实体(db_report_column_config 表)
│ ├── Models/
│ │ ├── EnumConverterType.cs # 转换类型枚举(None/ValueMap/LuaScript)
│ │ ├── ExportFormat.cs # 导出格式枚举(CSV/Excel)
│ │ ├── ReportPreviewInput.cs # 预览请求参数
│ │ ├── ReportExportInput.cs # 导出请求参数
│ │ └── DynamicReportResult.cs # 动态报表结果模型
│ ├── Services/
│ │ ├── LuaScriptEngine.cs # Lua 脚本引擎(MoonSharp 封装)
│ │ ├── DynamicReportService.cs # 动态报表服务(预览、导出)
│ │ └── ReportConfigService.cs # 配置管理服务(CRUD)
│ └── Repository/
│ └── DynamicReportRepository.cs # 数据访问层(SqlSugar)
├── Extensions/
│ └── ServiceCollectionExtensions.cs # DI 注册扩展
└── Cyclops.Reporting.csproj
保留所有权利
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on TJC.Cyclops.Reporting:
| Package | Downloads |
|---|---|
|
TJC.Cyclops.Web.Core
企服版框架中api核心功能项目,基于aspnetcore集成di、jwt、swagger、codefirtst、支持多种常见数据库、nacos配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.11.2 | 162 | 6/11/2026 |
| 2026.6.11.1 | 167 | 6/11/2026 |
| 2026.6.9.4 | 156 | 6/9/2026 |
| 2026.6.9.3 | 167 | 6/9/2026 |
| 2026.6.9.2 | 161 | 6/9/2026 |
| 2026.6.9.1 | 169 | 6/9/2026 |
| 2026.6.8.3 | 180 | 6/8/2026 |
| 2026.6.8.2 | 144 | 6/8/2026 |
| 2026.6.8.1 | 148 | 6/8/2026 |
| 2026.6.5.1 | 98 | 6/5/2026 |
| 2026.5.18.1 | 102 | 5/18/2026 |
| 2026.5.11.1 | 101 | 5/11/2026 |
| 2026.5.7.2 | 94 | 5/7/2026 |
| 2026.5.7.1 | 101 | 5/7/2026 |
| 2026.4.29.2 | 103 | 4/29/2026 |
| 2026.4.29.1 | 112 | 4/29/2026 |
| 2026.4.27.1 | 101 | 4/27/2026 |
| 2026.4.24.2 | 99 | 4/24/2026 |
| 2026.4.24.1 | 96 | 4/24/2026 |
| 2026.4.14.2 | 115 | 4/14/2026 |
用于泛型列表数据导出指定格式数据快捷工具集合