How can I find the number of active rows/read a particular cell/... in an Excel spreadsheet?

Thanks to J. H. Wright for posting this:


    package require tcom
    set excel [::tcom::ref createobject Excel.Application]
    $excel Visible 1
    set workbooks [$excel Workbooks]
    set workbook [$workbooks Add]
    set worksheets [$workbook Worksheets]
    set worksheet [$worksheets Item [expr 1]]
    set cells [$worksheet Cells]
    for {set row 1} {$row<=10} {incr row} {
        foreach column {A B C D E F G H I J K L} {
            $cells Item $row $column $column$row
        }
    }
    puts [[[$worksheet UsedRange] Columns] Count]
    puts [[[$worksheet UsedRange] Rows] Count]

[Show a similar result expressed in terms of CurrentRegion [L1 ].]

See also the Wiki pages on "Excel" and "tcom".