Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hallo

In Addition to the solutions in the link a solution to sort Sheet-tabs in Natural_sort_order

import re
rex = re.compile(r'(\d+|\D+)')

def natsort(stext):
    return [int(token) if token.isdigit()
              else token
              for token in rex.findall(stext)]

def sort_sheets_by_Name():
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.Sheets
    sheetnames = sheets.ElementNames
    for i, sheetname in enumerate(sorted(sheetnames, key=natsort)):
        sheets.moveByName(sheetname, i)

Hallo

In Addition to the solutions in the link a solution to sort Sheet-tabs in Natural_sort_order

import re
rex = re.compile(r'(\d+|\D+)')

def natsort(stext):
    return [int(token) if token.isdigit()
             else token
             for token in rex.findall(stext)]

def sort_sheets_by_Name():
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.Sheets
    sheetnames = sheets.ElementNames
    for i, sheetname in enumerate(sorted(sheetnames, key=natsort)):
        sheets.moveByName(sheetname, i)