Page 1 of 1

Ordering sheets

Posted: Mon Apr 02, 2012 11:55 pm
by Letto
I'd like to know how to order may sheets in an alphabetical order. For example I have many patients and each one has its own sheet. I need to order them to find a patient easily.
Thanks

Re: Ordering sheets

Posted: Tue Apr 03, 2012 12:59 am
by FJCC
I don't know of a built in way to do that. Here is a simple macro that should work

Code: Select all

If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
   GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If
Sheets = ThisComponent.Sheets
Names = Sheets.ElementNames
SortedList = BubbleSortList(Names) 'BubbleSortList is a macro in the Tools Library
for i = 0 to UBound(SortedList)
	Sheets.MoveByName(SortedList(i), i)
next i

Re: Ordering sheets

Posted: Tue Apr 03, 2012 1:01 am
by Villeroy
Python can sort lists:

Code: Select all

import uno
def sortSheets():
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.getSheets()
    c = sheets.getCount()
    t = sheets.getElementNames()
    l = list(t)
    l.sort()
    for n in range(c):
        sheets.moveByName(l[n],n)
g_exportedScripts = sortSheets,

Re: Ordering sheets

Posted: Tue Apr 03, 2012 8:10 am
by karolus
Hallo
@Villeroy:

slightly more readable:

Code: Select all

def sheets_sort():
    
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.getSheets()
    sheetnames = sorted( sheets.getElementNames() )
    for i, sheet in enumerate( sheetnames ):
        sheets.moveByName( sheet, i)
Karo

Re: Ordering sheets

Posted: Tue Apr 03, 2012 11:06 am
by Villeroy
karolus wrote:Hallo
@Villeroy:

slightly more readable:

Karo
Thank you. That's a lot more readable and shorter. I'm not very profiecient in Python programming and did not even search for a built-in function. Instead I accessed the list object I knew to be sortable.

Re: Ordering sheets

Posted: Tue Apr 03, 2012 11:33 am
by hanya
It seems Letto uses BrOffice.org 3.0.0 OOO300m9 which uses Python 2.3.X. sorted function is new feature of Python 2.4, so importing the function from __feature__ module is required, I suppose.

Re: Ordering sheets

Posted: Fri Nov 21, 2014 11:15 am
by kaybee1
Hi,
how to change that basic macro to sort all the sheets except the first and second, and a sheet named 'NoSortSheet'? I can not deal with it :( , please help.