2013-10-28 35 views

回答

1

SpreadsheetGear支持COUNTA功能。您可以將它作爲公式的一部分直接輸入到單元格中。或者你可以使用ISheet。 EvaluateValue(...)方法來評估一個公式,而不必將其實際輸入到單元格中。示例:

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

您也可以使用SpreadsheeGear API構建自己的計數例程。下面的代碼可能是一個很好的起點,出點:

int counter = 0; 
foreach (IRange cell in worksheet.Cells["A1:A12"]) 
{ 
    if (cell.ValueType != SpreadsheetGear.ValueType.Empty) 
     counter++; 
} 
+0

就我而言,我有這樣的產生的空文本結果字符串連接的公式,但這是不一樣'SpreadsheetGear.ValueType.Empty'。對我有效的是'if(cell.Text!= string.Empty)'。 – vwfreak