How to Format text in a Numbers 3.2 formula ?

Hello Experts,


I'm using Numbers text formulas to put calculations results in clear language.

Example : "If I have 5 apples and I give 3 away, then I'm left with 2 apples".


To this purpose I use the 'concatenate' function.

Example : CONCATENATE("If I have ";B1;" apples and I give"; B2;" away, then I'm left with"; B3;" apples")


That part works just fine.


Now, I would like to make the message easier to read, by using text format like bold and/or colours.

Example : "If I have 5 apples and I give 3 away, then I'm left with 2 apples".


This is where I need help, because Numbers won't allow me to change part of the text style : it's the whole sentence or nothing.

And I can't find any way to format (bold, italic ...) the result of a calculation cell.

Fragmenting the sentence in more parts and changing the format of the source cell doesn't work either.

I haven't find any way to get there so far, nor any post on that subject.


Many thanks in advance for your creative support !

Posted on Jun 20, 2014 7:57 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 22, 2014 9:10 AM

Wayne is right! You can achieve this effect within Numbers using AppleScript. Jacque's script was helpful. But you don't need to go through TextEdit or use gui scripting.


User uploaded file


The script below takes the text concatenated in a table cell (here "A1") and places it in a text box with specified words in bold.

Copy into AppleScript Editor, change any properties to match your setup, and click the green triangle 'run' button.


SG


--takes text from a cell, changes specified words to bold, and places in text box
property boldWords : {4, 5, 9, 15, 16} -- specify words to bold: here 4th, 5th, 9th, etc.
property textPosition : {0, 0} -- specify where to place text box - {horizontal offset,vertical offset}
property textWidth : 200 -- specify width of text box
tell application "Numbers" to tell front document to tell active sheet
  set myText to value of cell "A1" of first table --specify cell with concatenated text
  set myTextItem to make new text item ¬
  with properties {object text:myText, position:textPosition, width:textWidth}
  tell myTextItem's object text
  repeat with i from 1 to count boldWords
  tell word (boldWords's item i) to set font to "Helvetica-Bold"
  end repeat
  end tell
end tell
--end of script
4 replies
Question marked as Top-ranking reply

Jun 22, 2014 9:10 AM in response to JDS-UP

Wayne is right! You can achieve this effect within Numbers using AppleScript. Jacque's script was helpful. But you don't need to go through TextEdit or use gui scripting.


User uploaded file


The script below takes the text concatenated in a table cell (here "A1") and places it in a text box with specified words in bold.

Copy into AppleScript Editor, change any properties to match your setup, and click the green triangle 'run' button.


SG


--takes text from a cell, changes specified words to bold, and places in text box
property boldWords : {4, 5, 9, 15, 16} -- specify words to bold: here 4th, 5th, 9th, etc.
property textPosition : {0, 0} -- specify where to place text box - {horizontal offset,vertical offset}
property textWidth : 200 -- specify width of text box
tell application "Numbers" to tell front document to tell active sheet
  set myText to value of cell "A1" of first table --specify cell with concatenated text
  set myTextItem to make new text item ¬
  with properties {object text:myText, position:textPosition, width:textWidth}
  tell myTextItem's object text
  repeat with i from 1 to count boldWords
  tell word (boldWords's item i) to set font to "Helvetica-Bold"
  end repeat
  end tell
end tell
--end of script

Jun 21, 2014 11:53 AM in response to JDS-UP

Hi,


Here is a workaround, tested on Numbers 5.2 and OS X 10.9.3 (need GUI Scripting) :


This AppleScript need accessibility enabled.

You must select the cells. E.G. cells "B4:J4"

The TextEdit application should open a new document in RTF format (not as plain text), otherwise you can change this in the TextEdit preferences.

Run the AppleScript.

This script change the font of word (4, 5, 8, 15 and 16) in each cell to "Helvetica-Bold"


If you select cells "B4:J4", the script paste the text in cells "B5:J5", you can hide the fourth row after running the script.

If you want to paste in the selection (These cells will lose their formula.), remove the block `tell myTable .... end tell` in the script



Here is the AppleScript:


tell application "Numbers" -- works on Numbers  5.2
    try
        set myTable to first table of active sheet of document 1 whose class of selection range is range -- get selected table
    on error
        display alert "You must select some cells before running this script"
        return
    end try
    my gui_Scpt("c", "Numbers") -- copy Selected Cells to clipboard
    my changeTextStyle() -- in TextEdit
    tell myTable
        set c to address of column of cell 1 of selection range
        set r to address of row of last cell of selection range
        set selection range to cell (r + 1) of column c -- select cell in next row to paste below the selected cells
    end tell
    my gui_Scpt("v", "Numbers") -- paste the clipboard
end tell


on gui_Scpt(t, aName)
    tell application "System Events"
        tell process aName
            set frontmost to true
            keystroke t using command down
        end tell
    end tell
end gui_Scpt


on changeTextStyle()
    tell application "TextEdit"
        set newDoc to make new document
        my gui_Scpt("v", "TextEdit") -- paste cells as RTF 
        tell newDoc
            set tc to count paragraphs
            delete paragraph 1 -- blank line 
            delete last paragraph -- blank line 
            repeat with i from 1 to (tc - 2)
                tell paragraph i
                    set font of words 4 thru 5 to "Helvetica-Bold"
                    set font of words 8 to "Helvetica-Bold"
                    set font of words 15 thru 16 to "Helvetica-Bold"
                end tell
            end repeat
            my gui_Scpt("ac", "TextEdit") -- select all and copy to clipboard
            delay 0.2
            close without saving
        end tell
    end tell
end changeTextStyle


But you must learn AppleScript of TextEdit to edit text other than your example "If I have 5 apples and I give 3 away, then I'm left with 2 apples" or add others styles in this simple script.

Jun 20, 2014 10:12 AM in response to JDS-UP

Having some trouble finding my way around with the new Support Communities software...😟


Not sure how to do this in AppleScript either. It's not hard to control color and font, but, like the user interface, it's generally all or nothing. One could probably have a script mark up the text as html or markdown and export for viewing elsewhere, but not sure how this could be done solely within Numbers. Sorry.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to Format text in a Numbers 3.2 formula ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.