tiangong-doc tiangong-doc
首页
  • 天宫体系

    • 前端架构
    • 后端架构
    • 扩展功能
    • 打包部署
    • 更新日志
    • 辅助开发平台 (opens new window)
    • 权限平台部署包下载 (opens new window)
  • 基础组件

    • 工作流引擎(待整理)
    • 跨境加签客户端(待整理)
    • 权限平台(待整理)
  • 数字化工具

    • 数字魔方
    • 数据采集
    • 智能导入
    • 数字员工
    • 规则引擎(开发中)
    • 消息引擎(待开发)
    • 智能导出(待开发)
  • 业务算法

    • 南京业务体检(待整理)
    • 智慧长江(待整理)
  • 识别模型

    • 空箱识别(待整理)
    • 智能客服(待整理)
    • OCR识别(待整理)
    • 车牌识别(待整理)
    • 超市停留识别(待整理)
    • 危险品识别(待开发)
    • 超长车识别(待开发)
    • 车辆靠台(待开发)
    • 车辆占用(待开发)
  • 算法模型(待整理)
  • 风控模型(待整理)
  • 海关规则(待整理)
  • 危险品知识(待整理)
  • 组件设计文档(待整理)
  • 数据服务

    • 商品归类服务(待开发)
    • RECP贸易服务(待开发)
    • 商品价格服务(待开发)
    • 业务申报解答(待开发)
    • 报关单状态查询(待开发)
  • 常用开发工具

    • BASE64编解码工具 (opens new window)
    • MD5编码工具 (opens new window)
    • AES/DES加解密 (opens new window)
    • JWT解码工具 (opens new window)
    • ASCII编解码工具 (opens new window)
    • Unicode编解码工具 (opens new window)
    • UTF-8编解码工具 (opens new window)
    • 字符串编解码工具 (opens new window)
    • 通用进制转换工具 (opens new window)
    • 浮点数十进制转换 (opens new window)
    • 在线JSON解析 (opens new window)
    • 在线JS代码格式化工具 (opens new window)
    • CSS可视化工具 (opens new window)
    • XML格式化工具
    • SQL压缩/格式化工具 (opens new window)
    • JSON/XML在线转换 (opens new window)
    • JSON/YAML在线转换 (opens new window)
    • IP地址查询 (opens new window)
    • HTTP在线接口测试 (opens new window)
    • UUID在线生成器 (opens new window)
    • 随机数生成器 (opens new window)
    • 在线文本比对 (opens new window)
  • 研发标准规范(待整理)
  • 国产化适配
首页
  • 天宫体系

    • 前端架构
    • 后端架构
    • 扩展功能
    • 打包部署
    • 更新日志
    • 辅助开发平台 (opens new window)
    • 权限平台部署包下载 (opens new window)
  • 基础组件

    • 工作流引擎(待整理)
    • 跨境加签客户端(待整理)
    • 权限平台(待整理)
  • 数字化工具

    • 数字魔方
    • 数据采集
    • 智能导入
    • 数字员工
    • 规则引擎(开发中)
    • 消息引擎(待开发)
    • 智能导出(待开发)
  • 业务算法

    • 南京业务体检(待整理)
    • 智慧长江(待整理)
  • 识别模型

    • 空箱识别(待整理)
    • 智能客服(待整理)
    • OCR识别(待整理)
    • 车牌识别(待整理)
    • 超市停留识别(待整理)
    • 危险品识别(待开发)
    • 超长车识别(待开发)
    • 车辆靠台(待开发)
    • 车辆占用(待开发)
  • 算法模型(待整理)
  • 风控模型(待整理)
  • 海关规则(待整理)
  • 危险品知识(待整理)
  • 组件设计文档(待整理)
  • 数据服务

    • 商品归类服务(待开发)
    • RECP贸易服务(待开发)
    • 商品价格服务(待开发)
    • 业务申报解答(待开发)
    • 报关单状态查询(待开发)
  • 常用开发工具

    • BASE64编解码工具 (opens new window)
    • MD5编码工具 (opens new window)
    • AES/DES加解密 (opens new window)
    • JWT解码工具 (opens new window)
    • ASCII编解码工具 (opens new window)
    • Unicode编解码工具 (opens new window)
    • UTF-8编解码工具 (opens new window)
    • 字符串编解码工具 (opens new window)
    • 通用进制转换工具 (opens new window)
    • 浮点数十进制转换 (opens new window)
    • 在线JSON解析 (opens new window)
    • 在线JS代码格式化工具 (opens new window)
    • CSS可视化工具 (opens new window)
    • XML格式化工具
    • SQL压缩/格式化工具 (opens new window)
    • JSON/XML在线转换 (opens new window)
    • JSON/YAML在线转换 (opens new window)
    • IP地址查询 (opens new window)
    • HTTP在线接口测试 (opens new window)
    • UUID在线生成器 (opens new window)
    • 随机数生成器 (opens new window)
    • 在线文本比对 (opens new window)
  • 研发标准规范(待整理)
  • 国产化适配
  • EciReport导出
2024-09-10
目录

EciReport模板导出_Core

# 功能介绍

 基于模板导出Excel的功能
1

# 功能使用

有两个类一个是EciReport2003,另一个是EciReport2007。
区别:
EciReport2003 的模板是 xxx.xls的
EciReport2007 的模板是 xxx.xlsx
两个类的属性都是一样的,使用方法也是一样的,主要是根据模板来选择。
1
2
3
4
5

# EciReport2003类的属性

属性 说明 类型 默认值
ForceFormulaRecalculation 重新计算公式 bool false
Name 报表名称 string
Type 报表类型 string
TemplateFile 模板文件 string
DataSource 数据源 DataSet
ReportParam 参数 EntityBase
ListDetail 明细处理配置 List:EciReportDetail
TargetFileName 目标文件名 string
multiSheet 是否是多sheet bool

# EciReport2003类的方法

事件名称 说明 参数
EciReport2003 构造函数
AddDataTable 追加数据表 DataTable
AddDataTable 追加数据表 DataTable,tableName
Execute 执行导出第一页Sheet【EXCEL报表】
ExecuteSheet 导出指定索引的Sheet sheet索引:inputSheetIndex,table名称:headTableName
PrintLandscape 设置水平打印 landscape(true:横向打印,false:纵向打印),pagerSize
ToExcel 导出Excel
Save 保存到本地目录 文件名称:fileName

# EciReportDetail 类的属性

属性 说明 类型 默认值
Name 数据源的名称 string
StartRowIndex 起始行,注意:第一行的索引是1,不是0 int
RowIndex 模板行 int
TableIndex word导出模板专用 int 0

# 主从 完成

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
1
2

# 示例

# 模板示例

![[core_01_模板.png]]

# 代码示例1
EciReport2003 npoi = new EciReport2003();
DataSet dataset = new DataSet();
//准备主表信息
DataTable head = new DataTable();
head.TableName = "HEAD";
head.Columns.Add("username");
head.Columns.Add("testNo");
DataRow row = head.NewRow();
row["username"] = "测试";
row["testNo"] = "11";
head.Rows.Add(row);
dataset.Merge(head);

//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";//可以不加
npoi.DataSource = dataset;
//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });
npoi.AddDataTable(dt, "DATA");
npoi.Execute();

//下载excel
return npoi.ToExcel(context);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 导出结果

![[core_01_结果.png]]

# 导出主从(分组) 完成

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
在明细表中,通过K列,来进行分组
1
2
3

# 示例

# 模板示例

在表头,明细表中,添加K列,设置相同的值,代表是一组的 ![[core_02_模板.png]]

# 代码示例
EciReport2003 npoi = new EciReport2003();
               
//准备主表信息
DataTable head = new DataTable();
head.Columns.Add("username");
head.Columns.Add("K");
head.Columns.Add("SHEET_NAME");
DataRow row = head.NewRow();
row["username"] = "用户1";
row["SHEET_NAME"] = "表单1";
row["K"] = "K1";
head.Rows.Add(row);

DataRow row2 = head.NewRow();
row2["username"] = "用户2";
row2["SHEET_NAME"] = "表单2";
row2["K"] = "K2";
head.Rows.Add(row2);
npoi.AddDataTable(head, "HEAD");

//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";//可以不加

//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });
dt.Columns.Add("K");
dt.Rows[0]["K"] = "K1";
dt.Rows[1]["K"] = "K1";
dt.Rows[2]["K"] = "K2";
dt.Rows[3]["K"] = "K2";
npoi.AddDataTable(dt, "DATA");
npoi.Execute();

//下载excel
return npoi.ToExcel(context);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 导出结果

分不同的sheet显示结果 ![[core_02_结果1.png]] ![[core_02_结果2.png]]

# 仅导出明细

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
1
2

# 示例

# 模板示例

![[core_03_模板.png]]

# 代码示例
EciReport2003 npoi = new EciReport2003();
              
//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";

//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });

npoi.AddDataTable(dt, "DATA");
npoi.Execute();

//下载excel
return npoi.ToExcel(context);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 导出结果

![[core_03_结果.png]]

# Excel导出到Table添加超链接

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
添加超链接:添加列:columnName_LINK,
1
2
3

# 示例

# 模板示例

在代码中,给明细表的字段添加超链接: 给字段NAME添加,就是在表格中添加列NAME_LINK,设置url地址。 ![[core_04_模板.png]]

# 代码示例
EciReport2003 npoi = new EciReport2003();
              
//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";
//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });
dt.Columns.Add("name_LINK");
foreach (DataRow row in dt.Rows)
{
	row["name_LINK"] = "http://baidu.com";//测试超链接
}

npoi.AddDataTable(dt, "DATA");
npoi.Execute();

//下载excel
return npoi.ToExcel(context);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 导出结果

![[core_04_结果.png]]

# 导出设置偏移量

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
在模板中设置 $字段 % 3:向左偏移3个单元格;
1
2
3

# 示例

# 模板示例

向左偏移2个单元格:从F列偏移到D列; ![[core_05_模板.png]]

# 代码示例
EciReport2003 npoi = new EciReport2003();
//准备主表信息
DataTable head = new DataTable();
head.TableName = "HEAD";
head.Columns.Add("username");
DataRow row3 = head.NewRow();
row3["username"] = "测试";
head.Rows.Add(row3);
npoi.AddDataTable(head, "HEAD");

//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";//可以不加

//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });
npoi.AddDataTable(dt, "DATA");

npoi.Execute();

//下载excel
return npoi.ToExcel(context);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 导出结果

![[core_05_结果.png]]

# 多模板,多sheet导出

主表字段使用的 $ 开始 ,后面拼接表格列的字段名称
明细字段使用:#  开始 ,后面拼接表格列的字段名称
要执行多次:ExecuteSheet,指定sheet执行导出
1
2
3

# 示例

# 模板示例

![[core_06_模板1.png]] ![[core_06_模板2.png]]

# 代码示例
EciReport2003 npoi = new EciReport2003();
//准备主表信息
DataTable head = new DataTable();
head.TableName = "HEAD";
head.Columns.Add("username");
DataRow row3 = head.NewRow();
row3["username"] = "测试";
head.Rows.Add(row3);
npoi.AddDataTable(head, "HEAD");

DataTable dataA = dt;
dataA.TableName = "A";

DataTable dataB = new DataTable();
dataB.TableName = "B";
dataB.Columns.Add("name");
DataRow row = dataB.NewRow();
row["name"] = "nameB";
dataB.Rows.Add(row);

npoi.AddDataTable(dataB, "B");
npoi.AddDataTable(dataA, "DATA");
//模板
npoi.TemplateFile = EciCore.Runtime.ServerPath + @"\Template\岗位信息.xls";
npoi.TargetFileName = "岗位信息.xls";

//设置明细
npoi.ListDetail.Add(new EciReportDetail() { StartRowIndex = 5, Name = "DATA" });
npoi.Execute();

npoi.ListDetail = new List<EciReportDetail>() { new EciReportDetail() { Name = "B", StartRowIndex = 2 } };
npoi.ExecuteSheet(1, string.Empty);

//下载excel
return npoi.ToExcel(context);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 导出结果

![[core_06_结果1.png]] ![[core_06_结果2.png]]

最近更新
01
EciReport模板导出
09-09
02
Core权限平台接口
07-25
03
Java权限平台接口
07-25
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式