macosapplescriptosx-mavericksiworkapple-numbers

Hot get rich text of cells in Numbers


I want to convert rich text cell content of my numbers table to other formats like Markdown or HTML. But how do I get more then just plain text?

Maybe there's a solution how to set the selection range and copy it as rtf to the clipboard.

tell application "Numbers"
    get formatted value of cell 2 of row 2 of table 1 of sheet 1 of document of window 1
end tell

Solution

  • Here's a script to select the cell and then copy the contents to the clipboard which preserves the formatting:

    tell application "Numbers"
        tell table 1 of sheet 1 of document of window 1
            activate
            set selection range to cell 2 of row "2" --range "B2:B2"
        end tell
    
        tell application "System Events"
            tell process "Numbers"
                keystroke "c" using command down
            end tell
        end tell
    end tell