Skip to content

Create a separate sheet for each category in a column #1151

Answered by saulpw
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Everything is possible with the magic of Python! :)

I think something like this should work:

@FreqTableSheet.api
def freq_subsheets(sheet, rows):
    for r in rows:
        vs = copy(sheet.source)
        vs.name += "_" + valueNames(r.discrete_keys, r.numeric_key)
        vs.rows = copy(r.sourcerows)
        yield vs

FreqTableSheet.addCommand('g'+ENTER, 'open-rows', 'for vs in freq_subsheets(selectedRows): vd.push(vs)')

(It's important to put the push, selectedRows in the execstr itself (along with any cursor* or input()), as various things like the cmdlog and menu system look into the execstr for their functionality.)

[edited to include @DAVIDWALES improvements below]

Replies: 1 comment 15 replies

Comment options

You must be logged in to vote
15 replies
@saulpw
Comment options

@ghost
Comment options

@saulpw
Comment options

@ghost
Comment options

@saulpw
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants