1 ranges
Mauricio Baeza edited this page 2019-10-09 17:45:59 -05:00

Ranges

Cells

  • Get active cell
    cell = app.get_cell()
    app.msgbox(cell.name)
  • By address, in active sheet.
    cell = app.get_cell('B10')
    app.msgbox(cell.name)

    cell = app.get_cell(2, 4)
    app.msgbox(cell.name)
  • By position, first the row, then the column, in active sheet.
    cell = app.get_cell(2, 4)
    app.msgbox(cell.name)
  • Get cell in other sheet
    doc = app.get_document()
    sheet = doc['Sheet2']

    cell = sheet['A1']
    app.msgbox(cell.name)

    cell = sheet[2,4]
    app.msgbox(cell.name)

Ranges

IMPORTANT: By position is START_ROW:END_ROW, START_COLUMN:END_COLUMN

    doc = app.get_document()
    sheet = doc['Sheet1']

    # By address
    rango = sheet['A1:C11']
    app.msgbox(rango.name)

    # By range name
    rango = sheet['names']
    app.msgbox(rango.name)

    # By position
    rango = sheet[7:11,1:3]
    app.msgbox(rango.name)

TIP Don't get confused, the final row and column, should be where you need more one, because internally is used the function slice of python

Get column

    rango = sheet[:,5]
    app.msgbox(rango.name)

Get row

    rango = sheet[10]
    app.msgbox(rango.name)

Current region

    cell = app.get_cell()
    app.msgbox(cell.name)
    rango = cell.current_region
    app.msgbox(rango.name)

Next cell

  • Get next free cell after the current region
    cell = app.get_cell().current_region.offset()
    app.msgbox(cell.name)

Get visible

  • Get only visible cells in range, always return a tuple of ranges.
    for r in app.get_cell().current_region.visible:
        app.msgbox(r.name)

Get empty

  • Get only empty cells in range, always return a tuple of ranges.
    for r in app.get_cell().current_region.empty:
        app.msgbox(r.name)

Select cell or range

    doc = app.get_document()
    cell = doc.active['B2']
    cell.select()
    app.msgbox(cell.name)
    rango = doc.active['C5:F10']
    rango.select()

In range

  • Now if range it's container in other.
    r1 = doc.active['A1:B3']
    c1 = doc.active['E5']
    app.msgbox(c1.in_range(r1))

    c1 = doc.active['A2']
    app.msgbox(c1.in_range(r1))