2010-11-05 70 views
0

有沒有辦法在excel工作表中獲取最大數量的用戶填充單元格,而不需要通過一個範圍或每個excel電子表格迭代最大單元格?使用vb.net獲取最大單元格填充數

現在我有

Imports Excel = Microsoft.Office.Interop.Excel 
Private Sub DoStuff() 
     Dim oApp As New Excel.Application 
     Dim oWB As Excel.Workbook 
     Dim oSheet As Excel.Worksheet 

     oWB = oApp.Workbooks.Open(txtExcel.Text) 
     oSheet = CType(oWB.ActiveSheet, Excel.Worksheet) 

     For Each iCount As Integer in oSheet.Cells.Rows.Count 
     'get cell text for every row in a specific column' 
     dim sCellText as string = oSheet.Cells(iCount, 1).toString 
     'do stuff' 
     Next 
End Sub 

眼下oSheet.Cells.Rows.Count = 1048576和尋找通過片材有小於1000行數據。

回答

1

嘗試oSheet.UsedRange
在這裏,您可以檢查上面返回的Range實例中的列,以找出填充到特定列中的單元格。

OR

WorksheetFunction.CountA(range("A1:A20000"))

相關問題