Assigning a group of cells without iterating through them

So currently the way my python script assigns values to things is by going into each cell one by one and entering the value.

Is there a function that takes an array and outputs it to the selection/range?

My code is basically a “remove duplicates” solution that I mapped to Shift + Enter.

def RemoveDuplicates(*args):

    document = XSCRIPTCONTEXT.getDocument()
    sheet = document.CurrentController.ActiveSheet

    selection = document.getCurrentSelection()

    uniques = []
    for c in range(0,selection.Rows.getCount()):
        cell = selection.getCellByPosition(0,c)
        if cell.getString() not in uniques and len(cell.getString()) is not 0:
            uniques.append(str(cell.getString()))
        cell.String = ""

    if len(uniques) < selection.Rows.getCount():
        for u in range(0, len(uniques)):
            selection.getCellByPosition(0,u).String = str(uniques[u])

I’ve trolled through the docs but I can’t find anything.

Hallo

def remove_duplicates(*_):

    """
    remove duplicate entries
    in Selection of ***one*** column
    """

    doc = XSCRIPTCONTEXT.getDocument()
    sel = doc.CurrentSelection
    sheet = sel.Spreadsheet
    data = sel.DataArray
    out = []
    for row in data:
        if row[0] and not row in out:
            out.append(row)
    sel.clearContents(1+2+4+16) #Values, Dates, Strings, Formulas
    cursor = sheet.createCursorByRange( sel )
    cursor.collapseToSize( 1, len( out ))

    cursor.DataArray = out

and for LO>5.1:

def remove_duplicates(*_):
    """
    remove duplicate entries
    in Selection of ***one*** column
    """

    doc = XSCRIPTCONTEXT.getDocument()
    sel = doc.CurrentSelection
    data = sel.DataArray
    out = []
    for row in data:
        if row[0] and not row in out:
            out.append(row)
    sel.clearContents(1+2+4+16)
    shrink = sel[ :len(out), : ]
    shrink.DataArray = out

Oh. That’s great. Is there a difference between CurrentSelection and getCurrentSelection? Or does getCurrentSelection just return CurrentSelection anyway?

Thanks for the help!

CurrentSelection property is internally implemented using getter (getCurrentSelection) and setter (setCurrentSelection).

additional:
yes both returns the same object, from the python point of view …CurrentSelection : Attribut_access
…getCurrentSelection(): Method-acccess