EPPlus:将样式复制到范围 [英] EPPlus: Copy Style to a range

查看:457
本文介绍了EPPlus:将样式复制到范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在工作表中插入x个新行/列,并应用从中插入行/列的样式(backgroundcolor / border等)。

i would like to insert x-new rows/columns to a worksheet and apply the style of the row/column from which was inserted (backgroundcolor/border etc).

这是我添加新行的方式:

This is how i add new rows:

xlsSheet.InsertRow(18, RowCount);

然后我想将基本行的样式复制/应用到新插入的行中:

Then i would like to copy/apply the style of the "base" row to the new inserted rows:

for (int i = 0; i < RowCount; i++)
{
    xlsSheet.Cells[16, 1, 16, xlsSheet.Dimension.End.Column].Copy(xlsSheet.Cells[16 + i + 1, 1]);
}

但是此代码不会复制/应用基本行的样式。目前,我有一个互操作性的解决方法,但是与epplus相比需要花费数年的时间。 :-/

But this code doesnt copy/apply the style of the "base" rows. At this moment i have a workaround with interop, but this takes years in comparison to epplus. :-/

推荐答案

在4.0.4代码中:

if (copyStylesFromRow > 0)
{
    var cseS = new CellsStoreEnumerator<int>(_styles, copyStylesFromRow, 0, copyStylesFromRow, ExcelPackage.MaxColumns); //Fixes issue 15068 , 15090
    while(cseS.Next())
    {
        for (var r = 0; r < rows; r++)
        {
            _styles.SetValue(rowFrom + r, cseS.Column, cseS.Value);
        }
    }
}

它使用copyStylesFromRow值,但是由于代码的顺序,它使用新的行号。因此,如果您要从第3行开始插入4行,

it uses the copyStylesFromRow value but because of the sequence of code, it uses the new row numbers. So if you wanted to insert 4 rows starting in row 3:

workbook.Worksheets[1].InsertRow(3,4,6); 

这将从第3行开始插入4个新行,因为包括了第3行,您必须指出到第六行这是一个错误,但是您可以解决这个问题。

This inserts a 4 new rows starting in row 3, because row 3 is included, you have to point to the 6th row. This is a bug, but you can account for it.

这篇关于EPPlus:将样式复制到范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆