Ordering sheets

Creating a macro - Writing a Script - Using the API

Ordering sheets

Postby Letto » Mon Apr 02, 2012 11:55 pm

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
BrOffice.org 3.0.0 OOO300m9
OS Windows Xp
Letto
 
Posts: 1
Joined: Mon Apr 02, 2012 11:29 pm

Re: Ordering sheets

Postby FJCC » Tue Apr 03, 2012 12:59 am

I don't know of a built in way to do that. Here is a simple macro that should work
Code: Select all   Expand viewCollapse view
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
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7128
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Ordering sheets

Postby Villeroy » Tue Apr 03, 2012 1:01 am

Python can sort lists:
Code: Select all   Expand viewCollapse view
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,
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26631
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Ordering sheets

Postby karolus » Tue Apr 03, 2012 8:10 am

Hallo
@Villeroy:

slightly more readable:
Code: Select all   Expand viewCollapse view
def sheets_sort():
   
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.getSheets()
    sheetnames = sorted( sheets.getElementNames() )
    for i, sheet in enumerate( sheetnames ):
        sheets.moveByName( sheet, i)


Karo
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 845
Joined: Sat Jul 02, 2011 9:47 am

Re: Ordering sheets

Postby Villeroy » Tue Apr 03, 2012 11:06 am

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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26631
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Ordering sheets

Postby hanya » Tue Apr 03, 2012 11:33 am

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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 884
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Ordering sheets

Postby kaybee1 » Fri Nov 21, 2014 11:15 am

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.
OpenOffice 3.4.1 on WinXP/Win7/Win8
kaybee1
 
Posts: 1
Joined: Fri Nov 21, 2014 11:02 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests