简体   繁体   中英

Fast Range naming in Excel with C#

I'm working on a C# project where Excel files are extensively used. Most of the values in the sheets' cells are referred by assigning a name to a Range which identifies a single Cell. Until now all sheets were assembled iterating through single cells: each one was inserted singularly along its name and format, and obviously it was painfully slow. Trying to speed things up, I managed to insert arrays of data into one sheet, but Istill haven't found how to do the same thing with Range Names. I'm still stuck whith this code

for (var row = 1; row <= rows; row++)
{
    for (var column = 1; column <= columns; column++)
    {
        string refCell = GetExcelColumnName(column) + row.ToString();
        myExcelWorkbook.Names.Add(labels[row - 1, column - 1], sheet.Range[refCell , refCell ], true, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
    }
}

which is even slower than the previous version (it takes MINUTES to fill a list of ~10000 names). So I was wondering if there is a way to make this insertion in a faster way.

通常的方法是使范围名称覆盖多个单元格,从而使命名范围更少。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM