In VSTO Excel, how to detect data in cells?

后端 未结 5 1540
粉色の甜心
粉色の甜心 2020-12-19 07:38

A process to quickly detect whether there is data in a given worksheet or not, without actually looping through all of the rows/columns of the worksheet.

For my curre

5条回答
  •  盖世英雄少女心
    2020-12-19 08:01

    I work with VSTO and Excel for some time, at a very intense level, so I hope I can share things I've learned over the course of time with you.

    Based on the information you've provided, I'd recommend casting to an object array and working with that information instead. Basically you'd access the values as:

    object[,] arrayValues = (object[,])ExcelRange.Value2;
    

    arrayValues is a 2D array ([row,column]). Excel populates the array blazingly fast, and of course operations on the array will be very performant (don't worry about the performance of the boxing, it's NOT an issue, believe me).

提交回复
热议问题