【问题标题】:EPPlus v4 Worksheet.InsertRow >1024 bugEPPlus v4 Worksheet.InsertRow >1024 错误
【发布时间】:2020-04-18 08:52:59
【问题描述】:

发现用EPPlus v4(v4.5.3.3)插入> 1024行时,新插入的行下单元格中的公式被破坏,原来的一行消失了。

不幸的是,EPPlus v4 git 在 v5 中从 LGPL 迁移到商业许可模型时被归档。

在 NPOI 上试用时,它不能作为一个选项,因为它缺少一些关键功能,如 ShiftColumn/DeleteColumn,并且不能支持 Excel 表格、使用 ConditionalFormatting 的公式,以及通过添加的向后兼容属性MSExcel。

有没有 EPPlus v4 用户遇到过同样的情况并找到了好的解决方案?

【问题讨论】:

    标签: excel epplus npoi epplus-4


    【解决方案1】:

    在得到更好的答案之前,这是我在这种情况下使用的一种解决方法扩展方法:

    /// <summary>
    /// Providing Extensions to EPPlus/Excel
    /// </summary>
    public static class EPPlusExcelUtil
    {
        public const int EPPlusMaxRowInsertPerAction = 1024;
    
        /// <summary>
        /// This is a workaround to handle the case inserting > 1024 rows.
        /// <remarks>EPPlus v4 issue until v4.5.3.3</remarks>
        /// </summary>
        /// <param name="ws"></param>
        /// <param name="rowFrom">The position of the new row</param>
        /// <param name="rows">Number of rows to insert.</param>
        /// <param name="copyStylesFromRow">Copy Styles from this row. Applied to all inserted rows</param>
        public static void InsertRowEnhanced(this ExcelWorksheet ws, int rowFrom, int rows, int copyStylesFromRow = 0)
        {
            int batchOf1k = rows / EPPlusMaxRowInsertPerAction;
            for (int i = 0; i < batchOf1k; i++)
            {
                ws.InsertRow(rowFrom, EPPlusMaxRowInsertPerAction, copyStylesFromRow);
            }
    
            int rowsToInsertAfter1k = rows % EPPlusMaxRowInsertPerAction;
            if (rowsToInsertAfter1k != 0)
            {
                ws.InsertRow(rowFrom, rowsToInsertAfter1k, copyStylesFromRow);
            }
        }
    
    }
    

    【讨论】:

    • 我也有同样的问题,谢谢您的解决
    猜你喜欢
    • 2014-08-31
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2017-04-27
    相关资源
    最近更新 更多