How can I get the style such as Input, Text, Code, etc., of a selected cell? If a group of cells is selected, how can I get styles of all the cells in the group?

  • $\begingroup$ Programmatically? If it's just one cell, then a manual method: you can right-click on the cell's bracket, mouse over to "Style", and then see what's ticked... $\endgroup$ – J. M.'s discontentment Mar 23 '13 at 16:09
  • $\begingroup$ @J.M. yes programmatically. I wasn't precise. $\endgroup$ – Vladimir Mar 23 '13 at 17:58
"Style" /. Developer`CellInformation[nb]

where nb is the NotebookObject for the notebook you care about. Since you could have multiple cells selected, this will always return a list. It's also possible to have no cells selected, in which case CellInformation will return $Failed and the above code would throw an error.

| improve this answer | |
  • $\begingroup$ God, it's even in the help and I couldn't find it.. Thanks! $\endgroup$ – Vladimir Mar 24 '13 at 18:34
  • $\begingroup$ Thanks @John Fultz . I used your answer in formulating a routine to answer "Is there a shortcut to select all cells above the current cursor position?", picking out just the "Input" style cells to evaluate (which is what the asker was trying to do). $\endgroup$ – Bill N Nov 25 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.