pythonopenoffice.orgopenoffice-calcunopyuno

OpenOffice pyuno "select all"


Does anyone know how to use the OO uno bridge api to "select all" in a Calc sheet?

Alternatively, finding the maximum used row and column number would work.

What I want to do is apply a format to all the cells in the spreadsheet.

(The reason being that I'm saving the sheet as csv, so numbers are not accurately saved unless the format provides enough decimal places.)


Solution

  • Assuming you have already connected to OpenOffice and document is a spreadsheet that has been opened or created.

    #get the sheet you want to work with, I'm just going to grab the first sheet
    sheets = document.getSheets().createEnumeration()
    sheet = sheets.nextElement()
    
    #start with a range on the first cell
    range = sheet.getCellRangeByPosition( 0, 0, 0, 0 )
    
    #expand to full extend of the used area
    range.gotoEndOfUsedArea( True ) #true for expand selection
    
    #no do whatever formatting things you want to do