报错信息:

Number of rules must not exceed 3

[ArgumentException: Number of rules must not exceed 3]
NPOI.XSSF.UserModel.XSSFSheetConditionalFormatting.AddConditionalFormatting(CellRangeAddress[] regions, IConditionalFormattingRule[] cfRules) +870
NPOI.Extend.SheetExtend.CopyRows(ISheet sheet, Int32 startRowIndex, Int32 endRowIndex) +620
ExcelReport.SheetAdapter.CopyRow(Int32 rowIndex, Action processTemplate) +37
ExcelReport.TableFormatter`1.Format(SheetAdapter sheetAdapter) +485
ExcelReport.SheetFormatter.Format(IWorkbook workbook) +225
ExcelReport.Export.ExportToBuffer(String templateFile, SheetFormatter[] sheetFormatters) +46
ExcelReport.ExportHelper.ExportToWeb(String templateFile, String targetFile, SheetFormatter[] sheetFormatters) +294 使用源代码进行调试发现错误原因在于ExcelReport调用的NPOI.Extend这个拓展的问题
有问题的方法:CellExtend类下的AddConditionalFormattingRules方法


cell.Sheet.SheetConditionalFormatting.AddConditionalFormatting(regions, cfrs); 该方法的cfrs数组最大长度只能支持3个条件格式规则

可以改为循环添加条件格式规则或者按长度判断,长度大于3则循环添加

原方法:

        /// <summary>
/// 添加条件格式规则
/// </summary>
/// <param name="cell">单元格</param>
/// <param name="cfrs">条件格式规则</param>
public static void AddConditionalFormattingRules(this ICell cell, IConditionalFormattingRule[] cfrs)
{
CellRangeAddress[] regions =
{
new CellRangeAddress(cell.RowIndex, cell.RowIndex, cell.ColumnIndex, cell.ColumnIndex)
};
cell.Sheet.SheetConditionalFormatting.AddConditionalFormatting(regions, cfrs);
}

更改后的方法:

        #region 1.0 添加条件格式规则

        /// <summary>
/// 添加条件格式规则
/// </summary>
/// <param name="cell">单元格</param>
/// <param name="cfrs">条件格式规则</param>
public static void AddConditionalFormattingRules(this ICell cell, IConditionalFormattingRule[] cfrs)
{
CellRangeAddress[] regions =
{
new CellRangeAddress(cell.RowIndex, cell.RowIndex, cell.ColumnIndex, cell.ColumnIndex)
};
if (cfrs.Length <= )
{
cell.Sheet.SheetConditionalFormatting.AddConditionalFormatting(regions, cfrs);
}
else
{
foreach (var item in cfrs)
{
cell.Sheet.SheetConditionalFormatting.AddConditionalFormatting(regions, item);
}
} }

NPOI.Extend版本:1.0.3

ExcelReport版本:2.0.1

解决ExcelReport导出Excel报Number of rules must not exceed 3错误的问题的更多相关文章

  1. java导出excel报错:getOutputStream() has already been called for this response

    对于java导出excel报错的问题,查了很多都说是在使用完输出流以后调用以下两行代码即可 out.clear(); out = pageContext.pushBody(); 但这也许是页面上输出时 ...

  2. ExcelReport第一篇:使用ExcelReport导出Excel

    导航 目   录:基于NPOI的报表引擎——ExcelReport 下一篇:ExcelReport源码解析 概述 本篇将通过导出学生成绩的示例演示“使用ExcelReport导出Excel”的步骤. ...

  3. weblogic 12c下jxls导出excel报错Could not initialize class org.apache.poi.xssf.usermodel.XSSFVMLDrawing

    周一,开发反馈weblogic 12c下jxls导出excel报错,公司环境和UAT环境均报错,看日志如下: 2016-06-08 09:16:55,825 ERROR org.jxls.util.T ...

  4. 解决C#导出excel异常来自 HRESULT:0x800A03EC的方法 .

    解决C#导出excel异常来自 HRESULT:0x800A03EC的方法 .   xlBook.SaveAs(FilePath,Microsoft.Office.Interop.Excel.XlFi ...

  5. .net解决数据导出excel时的格式问题

    在项目中一般都需要将报表数据导出到EXCEL中,但经常出现导出长串数据(如身份证)到EXCEL中后显示为科学计数法的格式,或者报表中显示为001的数据导出到Excel后成了1的格式. 下面简单介绍一下 ...

  6. 解决poi导出Excel异常org.openxmlformats.schemas.spreadshe

    JAVA报表 POI未捕获到 servlet OUTEXCEL 的其中一个服务方法中抛出的异常.抛出的异常:java.lang.NoClassDefFoundError: org.openxmlfor ...

  7. 解决HTML导出Excel表数字变成科学计数法

    - js 中导出excel 较长数字串会变成科学计数法 在做项目中,碰到如题的问题.比如要将居民的信息导出到excel中,居民的身份证号码因为长度过长(大于10位),excel会自动的将过长的数字串转 ...

  8. NPOI导出EXCEL报_服务器无法在发送 HTTP 标头之后追加标头

    虽然发表了2篇关于NPOI导出EXCEL的文章,但是最近再次使用的时候,把以前的代码粘贴过来,居然报了一个错误: “服务器无法在发送 HTTP 标头之后追加标头” 后来也查询了很多其他同学的文章,都没 ...

  9. java解决poi导出excel文字水印,导出excel不可操作问题

    首先需求是用户提出导出excel数据需使用水印备注其用途: 其实就是在导出excel的同时带有自定义文字水印的导出. 那么我们首先想到的肯定是以一个什么样的思路去解决该问题,首先查找poi导出exce ...

随机推荐

  1. 串口线接Linux设备U盘安装系统和直接安装设备接显示屏2种方式不同

    Firmware Bug]: TSC_DEADLINE disabled due to Errata; please update microcode to version: 0x22 (or lat ...

  2. asp.net core 应用docke部署到centos7

    前言 前期准备 win10 (不要安装hyper-V) VMware-Workstation-Pro/15.0 Xshell6 (非必需) VS2019 以上环境请自行安装 都是默认安装没什么可说的 ...

  3. WordCloud教程(上)

    先贴代码: import wordcloud,jieba with open('datas/1.txt') as rt:#,encoding='utf-8' comment_text=rt.read( ...

  4. nova卸载volume源码分析

    基于llvm +iscsi协议进行分析 1.客戶端接受请求并路由到 VolumeAttachmentController 其对应的restfull请求格式如下:delete /servers/{ser ...

  5. JS手写call、bind、apply

    call方法的实现 Function.prototype.MyCall = function(content,...args){ const self = content || window; con ...

  6. 开始进行lammps手册的学习啦,跟着Manual一边翻译一边做吧!(转载)

    转载自:http://blog.sina.com.cn/s/blog_64813e370100ngsz.html 注明:黄色部分基本上为不懂的部分,红色字体为所做注释 一.各种文件的介绍: 1 in ...

  7. Git-commit-中添加表情

    git commit 中使用表情 我们经常可以在github上看到国外大佬的commit信息中有很多可爱的表情,这是怎么做到的呢? ok,可以这样使用哦:git commit -m '提交信息 :em ...

  8. Vue 通过调用百度API获取地理位置-经度纬度省份城市

    一.首先在百度api注册获得ak密钥 二.新建js文件,我命名为loadBMap.js,里面创建script,代码如下: /** * 加载地图 * @param {Function} callback ...

  9. 基于伪分布式Hadoop搭建Hive平台详细教程

    一.搭建环境的前提条件 环境:Linux系统 Hadoop-2.6.0 MySQL 5.6 apache-hive-2.3.7 这里的环境不一定需要和我一样,基本版本差不多都ok的,所需安装包和压缩包 ...

  10. 【从零开始撸一个App】PKCE

    一个成功的App背后肯定有一堆后端服务提供支撑,认证授权服务(Authentication and Authorization Service,以下称AAS)就是其中之一,它是约束App.保障资源安全 ...