Get the Number of Rows in Column of a worksheet

后端 未结 1 1836
我在风中等你
我在风中等你 2020-12-19 15:31

I have an Excel sheet as follows:

Id   Name   Address
-------------------
1    t1     Add1
2           Add2
3

I want to get the count of no

相关标签:
1条回答
  • 2020-12-19 16:15

    Try something like this:

    $xl = New-Object -COM "Excel.Application"
    $xl.Visible = $true
    
    $wb = $xl.Workbooks.Open("C:\path\to\your.xlsx")
    $ws = $wb.Sheets.Item(1)
    
    $rows = $ws.UsedRange.Rows.Count
    
    foreach ( $col in "A", "B", "C" ) {
      $xl.WorksheetFunction.CountIf($ws.Range($col + "1:" + $col + $rows), "<>") - 1
    }
    
    $wb.Close()
    $xl.Quit()
    
    0 讨论(0)
提交回复
热议问题