0

How can I check if specific SpreadsheetGear IRange contains values (=Non-blank cells)?

In Excel, I could utilize COUNTA function but there is no such in SpreadsheetGear.

Nuts
  • 2,755
  • 6
  • 33
  • 78

1 Answers1

1

SpreadsheetGear does support the COUNTA function. You can input it as part of a formula directly into a cell. Or you can use the ISheet.EvaluateValue(...) method to evaluate a formula without actually entering it into a cell. Example:

// Count the number of non-empty cells in A1:A12 on the specified worksheet
double count = (double)worksheet.EvaluateValue("COUNTA(A1:A12)");

You could build your own count routine using SpreadsheeGear API as well. The code below might be a good starting-out point:

int counter = 0;
foreach (IRange cell in worksheet.Cells["A1:A12"])
{
    if (cell.ValueType != SpreadsheetGear.ValueType.Empty)
        counter++;
}
Tim Andersen
  • 3,014
  • 1
  • 15
  • 11
  • In my case, I had string concatenation formulas that produced an empty text result, but this is not the same as `SpreadsheetGear.ValueType.Empty`. What worked for me was `if (cell.Text != string.Empty)`. – vwfreak Aug 28 '14 at 15:42