TJC.Cyclops.Reporting
2026.6.5.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TJC.Cyclops.Reporting --version 2026.6.5.1
NuGet\Install-Package TJC.Cyclops.Reporting -Version 2026.6.5.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="TJC.Cyclops.Reporting" Version="2026.6.5.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TJC.Cyclops.Reporting" Version="2026.6.5.1" />
<PackageReference Include="TJC.Cyclops.Reporting" />
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 TJC.Cyclops.Reporting --version 2026.6.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TJC.Cyclops.Reporting, 2026.6.5.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 TJC.Cyclops.Reporting@2026.6.5.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=TJC.Cyclops.Reporting&version=2026.6.5.1
#tool nuget:?package=TJC.Cyclops.Reporting&version=2026.6.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Cyclops.Reporting
Cyclops.Framework 框架中的报表生成组件,支持静态泛型报表和动态 SQL 报表两种模式。
功能特性
静态报表(原有功能)
基于泛型 List<T> 的报表导出,通过特性标注控制列信息:
- 支持 CSV 和 Excel(.xlsx/.xls)格式导出
- 使用
[ReportDescription]特性自定义列标题、排序、格式 - 使用
[ReportIgnore]特性忽略不需要导出的属性 - 支持 bool、DateTime、Enum 等类型的自动转换
- 支持自定义委托转换
动态报表(新增功能)
基于 Lua 脚本的动态 SQL 报表系统:
- Lua 脚本生成 SQL:支持动态条件拼接
- 列值转换:支持 None / ValueMap / LuaScript 三种转换类型
- 报表预览:支持前 N 行数据预览
- 报表导出:支持 CSV 和 Excel 格式
- 内置函数:HTTP、JSON、字符串、日期、加密、正则、日志等
技术栈
- .NET 8.0
- MoonSharp(Lua 脚本引擎)
- SqlSugar(通过 Cyclops.Orm)
- NPOI(Excel 处理)
安装
<PackageReference Include="TJC.Cyclops.Reporting" Version="2026.6.2.1" />
使用方式
静态报表
using Cyclops.Reporting;
using Cyclops.Reporting.Attrs;
// 定义数据模型
public class Hospital
{
[ReportDescription("医院名称", 1)]
public string Name { get; set; }
[ReportDescription("是否重要", 2, "重要,不重要")]
public bool IsImportant { get; set; }
[ReportDescription("创建时间", 3, datetimeFormat: "yyyy-MM-dd")]
public DateTime CreateTime { get; set; }
[ReportIgnore]
public string InternalField { get; set; }
}
// 使用
var data = new List<Hospital> { ... };
var report = new Report<Hospital>(data);
// 导出到文件
report.Export("医院信息.xlsx");
report.Export("医院信息.csv");
动态报表
1. 注册服务
using Cyclops.Reporting.Extensions;
builder.Services.AddCyclopsReporting();
2. 配置报表
报表配置存储在数据库中,包含两张表:
report_config(报表主配置)
| 字段 | 说明 |
|---|---|
| Id | 主键(雪花ID) |
| Name | 报表名称 |
| SqlTemplate | SQL 模板(Lua 脚本) |
| Description | 报表描述 |
| PreviewRows | 预览行数(默认 100) |
| LuaScript | 列转换用的 Lua 脚本 |
| Status | 状态(1=启用,0=禁用) |
report_column_config(列转换配置)
| 字段 | 说明 |
|---|---|
| Id | 主键 |
| ReportConfigId | 关联报表配置ID |
| ColumnName | 原始列名 |
| DisplayName | 显示列名 |
| SortNo | 排序号 |
| ConverterType | 转换类型:None / ValueMap / LuaScript |
| ConverterConfig | 转换配置 |
| IsVisible | 是否显示 |
3. SQL 模板示例
SQL 模板使用 Lua 脚本,接收 params 参数,返回 SQL 字符串:
local sql = "SELECT u.user_name, u.create_time, d.dept_name FROM sys_user u LEFT JOIN sys_dept d ON u.dept_id = d.id WHERE 1=1"
if params.status then
sql = sql .. " AND u.status = @status"
end
if params.startTime then
sql = sql .. " AND u.create_time >= @startTime"
end
if params.keyword and params.keyword ~= "" then
sql = sql .. " AND u.user_name LIKE @keyword"
end
return sql
4. 列转换 Lua 脚本示例
-- 定义转换函数
function GetUserName(userId)
local resp = http_get("https://a.b.c/api/user/" .. userId)
if resp then
return resp
end
return ""
end
function GetStatusText(value)
local map = {["1"]="启用", ["0"]="禁用"}
return map[tostring(value)] or ""
end
5. 使用服务
using Cyclops.Reporting.Dynamic.Services;
using Cyclops.Reporting.Dynamic.Models;
public class ReportController
{
private readonly DynamicReportService _reportService;
private readonly ReportConfigService _configService;
// 预览报表
public async Task Preview()
{
var dt = await _reportService.PreviewAsync(
reportConfigId: 1,
sqlParams: new Dictionary<string, object>
{
{ "status", 1 },
{ "startTime", DateTime.Now.AddDays(-30) }
},
previewRows: 50
);
}
// 导出报表
public async Task Export()
{
var stream = await _reportService.ExportAsync(
reportConfigId: 1,
sqlParams: new Dictionary<string, object>(),
format: ExportFormat.Excel
);
// 保存到文件
using var fs = new FileStream("报表.xlsx", FileMode.Create);
await stream.CopyToAsync(fs);
}
// 保存报表配置
public async Task SaveConfig()
{
var config = new DbReportConfig
{
Name = "用户报表",
SqlTemplate = "local sql = 'SELECT ...' return sql",
LuaScript = "function GetUserName(id) ... end",
PreviewRows = 100,
Status = 1
};
var id = await _configService.SaveConfigAsync(config);
}
// 保存列配置
public async Task SaveColumns()
{
var columns = new List<DbReportColumnConfig>
{
new DbReportColumnConfig
{
ColumnName = "user_name",
DisplayName = "用户名",
SortNo = 1,
ConverterType = "None"
},
new DbReportColumnConfig
{
ColumnName = "status",
DisplayName = "状态",
SortNo = 2,
ConverterType = "ValueMap",
ConverterConfig = "{\"1\":\"启用\",\"0\":\"禁用\"}"
},
new DbReportColumnConfig
{
ColumnName = "user_id",
DisplayName = "用户姓名",
SortNo = 3,
ConverterType = "LuaScript",
ConverterConfig = "GetUserName(value)"
}
};
await _configService.SaveColumnConfigsAsync(1, columns);
}
}
Lua 引擎内置函数
| 类别 | 函数 | 说明 |
|---|---|---|
| HTTP | http_get(url) |
GET 请求 |
| HTTP | http_post(url, body) |
POST 请求 |
| JSON | json_parse(str) |
JSON 解析 |
| JSON | json_stringify(obj) |
JSON 序列化 |
| 字符串 | string_format(fmt, ...) |
格式化 |
| 字符串 | string_split(str, sep) |
分割 |
| 字符串 | string_match(str, pattern) |
正则匹配 |
| 日期 | date_format(date, fmt) |
日期格式化 |
| 日期 | date_now() |
获取当前时间 |
| 加密 | md5(str) |
MD5 哈希 |
| 加密 | sha256(str) |
SHA256 哈希 |
| 加密 | base64_encode(str) |
Base64 编码 |
| 加密 | base64_decode(str) |
Base64 解码 |
| 正则 | regex_match(str, pattern) |
正则匹配 |
| 正则 | regex_replace(str, pattern, replacement) |
正则替换 |
| 日志 | log_info(message) |
信息日志 |
| 日志 | log_error(message) |
错误日志 |
项目结构
Cyclops.Reporting/
├── Core/ # 静态报表
│ ├── ReportBase.cs # 基类
│ ├── ReportColumn.cs # 列信息
│ ├── ReportCsv.cs # CSV 导出
│ └── ReportExcel.cs # Excel 导出
├── Dynamic/ # 动态报表
│ ├── Entities/
│ │ ├── DbReportConfig.cs # 报表配置实体
│ │ └── DbReportColumnConfig.cs # 列配置实体
│ ├── Models/
│ │ ├── EnumConverterType.cs # 转换类型枚举
│ │ ├── ExportFormat.cs # 导出格式枚举
│ │ ├── ReportPreviewInput.cs # 预览请求模型
│ │ ├── ReportExportInput.cs # 导出请求模型
│ │ └── DynamicReportResult.cs # 报表结果模型
│ ├── Services/
│ │ ├── LuaScriptEngine.cs # Lua 脚本引擎
│ │ ├── DynamicReportService.cs # 动态报表服务
│ │ └── ReportConfigService.cs # 配置管理服务
│ └── Repository/
│ └── DynamicReportRepository.cs # 数据访问层
├── Attrs/
│ ├── ReportDescriptionAttribute.cs # 列描述特性
│ └── ReportIgnoreAttribute.cs # 忽略特性
├── Extensions/
│ └── ServiceCollectionExtensions.cs # DI 扩展
└── Report.cs # 静态报表入口
依赖
- Cyclops.Common
- Cyclops.Orm
- MoonSharp
许可证
保留所有权利
| 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
- MoonSharp (>= 2.0.0)
- SqlSugarCore (>= 5.1.4.214)
- System.Security.Cryptography.Xml (>= 10.0.8)
- TJC.Cyclops.Common (>= 2026.6.5.1)
- TJC.Cyclops.Orm (>= 2026.6.5.1)
NuGet packages (1)
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配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.9.4 | 172 | 7/9/2026 |
| 2026.7.9.3 | 159 | 7/9/2026 |
| 2026.7.9.2 | 163 | 7/9/2026 |
| 2026.7.9.1 | 163 | 7/9/2026 |
| 2026.7.8.2 | 145 | 7/8/2026 |
| 2026.7.8.1 | 154 | 7/8/2026 |
| 2026.7.6.1 | 163 | 7/6/2026 |
| 2026.7.1.1 | 169 | 7/1/2026 |
| 2026.6.24.1 | 178 | 6/24/2026 |
| 2026.6.23.1 | 177 | 6/23/2026 |
| 2026.6.22.2 | 160 | 6/22/2026 |
| 2026.6.22.1 | 165 | 6/22/2026 |
| 2026.6.11.2 | 194 | 6/11/2026 |
| 2026.6.11.1 | 197 | 6/11/2026 |
| 2026.6.9.4 | 179 | 6/9/2026 |
| 2026.6.9.3 | 187 | 6/9/2026 |
| 2026.6.9.2 | 182 | 6/9/2026 |
| 2026.6.9.1 | 188 | 6/9/2026 |
| 2026.6.8.3 | 203 | 6/8/2026 |
| 2026.6.5.1 | 117 | 6/5/2026 |
Loading failed
用于泛型列表数据导出指定格式数据快捷工具集合