ok, never noticed that print() can show real type name.
so cells is in fact a Range object. this is ok
► sheet.cells.address
"$1:$1048576"
► sheet.cells.rows.count
1048576
► sheet.cells.columns.count
16384
this is same as microsoft says at [Login to see the link],
that cells is a Range object that represents all the cells on the worksheet
as microsoft says at [Login to see the link],
if using cells as function, then parameters are used by function item()
Because the default member of Range forwards calls with parameters to the Item property, you can specify the row and column index immediately after the Cells keyword instead of an explicit call to Item.
[Login to see the link]
Syntax:
expression.Item (RowIndex Required, ColumnIndex Optional)
now the problem is at item()
function.
it has two parameters, second parameter is optional
but in luart I can only use one parameter, why?
maybe there is a bug in detecting Optional
parameter
► sheet.cells:item(2, 3)
>>> COM error: unknown error
► sheet.cells:item(2, 3).address
>>> COM error: unknown error
► sheet.cells:item(2, 3, 4)
>>> COM error: bad parameter count
► sheet.cells:item(16384 + 3).address
"$C$2"
in Excel VBA:
Sub tee()
Set Sheet = ActiveSheet
Debug.Print Sheet.Cells(16384 + 3).Address
Debug.Print Sheet.Cells(2, 3).Address
End Sub
got:
$1:$1048576
$C$2
$C$2
now I can define a similar function:
function cells(range, row, column)
if column == nil then return range:item(row) else
row = row + range.row - 1
column = column + range.column - 1
return range.parent.cells:item(range.parent.cells.columns.count * (row - 1) + column)
end end
► cells(sheet.cells,2,3).address
"$C$2"
► cells(sheet.cells,1,1).address
"$A$1"
► cells(sheet.cells,1,2).address
"$B$1"
► cells(sheet.cells,2,1).address
"$A$2"
► cells(sheet.cells, 2*16384+4).address
"$D$3"
► cells(sheet:range("B2:C6"), 1, 1).address
"$B$2"
► cells(sheet:range("B2:C6"), 2, 1).address
"$B$3"
► cells(sheet:range("B2:C6"), 2, 6).address
"$G$3"
same as VBA:
Sub tee()
Set Sheet = ActiveSheet
Debug.Print Sheet.Range("B2:C6").Cells(2, 6).Address
End Sub
get: $G$3