解决ExcelReport导出Excel报Number of rules must not exceed 3错误的问题

报错信息:

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 <= 3)
            {
                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 

 

转载于:https://www.cnblogs.com/townsend/p/7544174.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Excel Report Builder<br>Excel Report 万能表平台<br>Excel 使用WEB服务(webservice)访问远程数据库<br>使用本软件可以使你的应用系统(数据库)和excel相连。<br>可以把它嵌入到你的应用系统里,做为应用系统的外挂程序。<br>可以利用excel强大的编辑功能,随心所欲地开发出精美的表。<br>本软件基于Web Service(Web服务)新技术,所以它支持web网络,<br>可以通过Internet访问远程数据。<br>只要你稍懂SQL,就可以在Excel Report 万能表平台上设计表。<br>通过设置字段,参数等信息来设计表。<br>BI智能表,支持透视表。<br>提供存储过程接口,便于用户二次开发。<br>有用户管理,表权限的管理。<br>支持多语种。 <br>软件环境:<br> 客户端: Windows 2000及以上版本,Microsoft Office 2000及以上版本<br> 服务器端:Windows和Linux都可以,jsdk1.4,tomcat5<br> 数据库:支持Oracle, SQL Server 等数据库。<br>下载地址:<br> SQL Server SP3:<br>http://203.208.248.203:81/pan/Excel/sql2ksp3.exe<br>SQL Server SP4:<br>http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXE<br>表安装包:<br>http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exe<br>http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exe<br><br><br>http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rar<br>联系方式:<br> http://pansoft.ik8.com<br> QQ: 10124900<br>MSN: bear_pan@hotmail.com<br>E_Mail: bear_pan@163.com<br><br><br>Excel Report Builder<br>Excel Report Builder is an easy and convenient tool for the creation and customization of reports which takes advantage of the formatting and presentation capabilities of Microsoft Excel. The program allows the rapid construction of reports.A GUI style design environment, which allows the user to design their reports visually inside MS Excel. Reports can be saved and then viewed and printed as pure Excel documents. <br>The reports are created and printed rapidly.In fact, it is by harnassing the power of Excel that gives Excel Report Builder these abilities.No technical knowledge is needed in order for the user to customise his or her own reports. <br><br>Key Features of the Database Report Builder for Excel include:<br> Report creation using Microsoft Excel<br> Get data through webservice,so you can get remote data <br> Support of the SQL-queries for the data sets creation<br> Calling of the stored procedures for the data sets creation<br> Creation of the reports with parameters<br> Work with the Microsoft Excel macros<br> Charts creation in a report<br><br>Software:<br> Client: Windows 2000 or above,Microsoft Office 2000 or above<br> Server: jsdk1.4,tomcat5<br> Database: Oracle or SQL Server <br>Download:<br>SQL Server SP3:<br>http://203.208.248.203:81/pan/Excel/sql2ksp3.exe<br>SQL Server SP4:<br>http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXE<br>Excel Report Builder:<br>http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exe<br>http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exe<br><br><br>http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rar<br><br><br>Contact:<br> http://pansoft.ik8.com <br> QQ: 10124900<br>MSN: bear_pan@hotmail.com<br>E_Mail: bear_pan@163.com<br><br>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值