How do i convert a neat numbers table to a neat html table?

is there an easy way to do this? As a web designer i often have to put huge tables of data into a page and to do this all by hand is a pain. So i am looking for a way to automate the process of noting down all that <table> <tr> <td> </td> </tr> </table> stuff around my table cells.

Any idea anyone?

Thanks in advance


dieselross

G5, Mac OS X (10.5.8)

Posted on Jun 1, 2011 6:34 AM

Reply
14 replies

Jun 1, 2011 7:09 AM in response to dieselross

I do not think there is a direct Numbers-to-HTML path.


If the source of the data is Numbers then I would look at using an Applescript or Automator script to take the data from a particular table of a sheet in a file and write it to an html file which you can include or copy.


The other option is to emit the data from its' original source as a CSV and write a perl script or Applescript to manipulate the data directly (rather then going through Numbers).


Lastly (And this will be slow because you already said you tables are large)... you can make a new table in Numbers (this works so long as you tables are generally the same size) and make it refer to your original table and concatenate the cell start string and ending string around each cell, the row start and end around groups of cells and the table start and stop strings around the rows. When I have to do this I go make a table in SeaMonkey composer, format is like I want, view the source, copy the source (for reference) and fill in the cell contents.


I hope this helps.


Wayne

Jun 1, 2011 7:48 AM in response to dieselross

dieselross wrote:


Excellent way to do it. A bit of a workaround...

...Too bad it can't be done directly from Numbers.

Thanks for the feedback. I don't get to worked-up about using multiple tools when they are all a part of the basic set delivered with the OS that Numbers runs in. Whether they are housed under one app's name or another isn't an issue, especially when we're talking about an operation that takes maybe 30 seconds total.


Jerry

Jun 1, 2011 8:03 AM in response to Jerrold Green1

Jerrold Green1 wrote:


I don't get to worked-up about using multiple tools when they are all a part of the basic set delivered with the OS that Numbers runs in. Whether they are housed under one app's name or another isn't an issue, especially when we're talking about an operation that takes maybe 30 seconds total.

Of course you're right! I think it was just that i am a bit spoiled by the elegant and intuitive way the OS and the applications usually work. Maybe i expressed myself a bit weird, i'm not a native speaker so please accept my apologies. What you suggested is excellent and will save me hours of work. Thanks a lot.

Jun 1, 2011 12:37 PM in response to dieselross

Here is a script doing the entire job with a single call.


--{code}

--[SCRIPT table_to_html]

(*

Enregistrer le script en tant que Script : table_to_html.scpt

déplacer le fichier ainsi créé dans le dossier

<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:

Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.


Sélectionner une table dans le panneau des vignettes d'un document Numbers.

Aller au menu Scripts , choisir Numbers puis choisir “table_to_html”

Le script copie la table,

la colle dans un nouveau document RTF de TextEdit,

enregistre celui-ci au format html,

ouvre ce dernier avec Safari

et enfin affiche le source html.


--=====


L’aide du Finder explique:

L’Utilitaire AppleScript permet d’activer le Menu des scripts :

Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.

Cochez la case “Afficher le menu des scripts dans la barre de menus”.

Sous 10.6.x,

aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript

puis cocher la case “Afficher le menu des scripts dans la barre des menus”.


--=====


Save the script as a Script: table_to_html.scpt


Move the newly created file into the folder:

<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:

Maybe you would have to create the folder Numbers and even the folder Applications by yourself.


Select a table in the thumbnail pane of a Numbers document.

Go to the Scripts Menu, choose Numbers, then choose “table_to_html”

The script copy the table

paste in a new TextEdit RTTF document

save this one as Html

open it in Safari

and at last reveal the Html source.


--=====


The Finder’s Help explains:

To make the Script menu appear:

Open the AppleScript utility located in Applications/AppleScript.

Select the “Show Script Menu in menu bar” checkbox.

Under 10.6.x,

go to the General panel of AppleScript Editor’s Preferences dialog box

and check the “Show Script menu in menu bar” option.


--=====


Yvan KOENIG (VALLAURIS, France)

2011/06/01

*)

--=====


on run

local nom_Tedit, menuName, path_html

my activateGUIscripting()


(*

copy the selected table

*)

my raccourci("Numbers", "c", "c")


(*

create an unique name

*)

set nom_Tedit to do shell script "date +_%Y%m%d_%H%M%S"


(*

create a blank TextEdit document

*)

tell application "TextEdit"


makenewdocumentwith properties {name:nom_Tedit}

end tell


(*

grab the name of the menu item "convert to format wxyk"

*)

set menuName to my get_menu_name("TextEdit", 5, 4) (* Format > Convertir au format xxx *)


(*

if the menu name contains RTF, trigger it

*)

if menuName contains "RTF" then my raccourci("TextEdit", "t", "cs")


(*

paste in the TextEdit RTF document

*)

my raccourci("TextEdit", "v", "c")


(*

save as html

*)

my save_as_html("TextEdit")


(*

grab the UNIX full path of the new html file

and close it.

*)

tell application "TextEdit"

set path_html to path of document 1


closedocument 1

end tell


(*

open the html file in Safari

*)

tell application "Safari"


openpath_html

end tell


(*

open the source

*)

my raccourci("Safari", "u", "ca")

end run


--=====


on activateGUIscripting()


(* to be sure than GUI scripting will be active *)

tell application "System Events"

if not (UI elements enabled) then set (UI elements enabled) to true

end tell

end activateGUIscripting


--=====

(*

==== Uses GUIscripting ====

*)

(*

This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.

It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.


I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.

*)

on raccourci(a, t, d)

local k

tell applicationa to activate

tell application "System Events" to tell application process a

set frontmost to true

try

t * 1

if d is "" then


key codet

else if d is "c" then


key codetusing {command down}

else if d is "a" then


key codetusing {option down}

else if d is "k" then


key codetusing {control down}

else if d is "s" then


key codetusing {shift down}

else if d is in {"ac", "ca"} then


key codetusing {command down, option down}

else if d is in {"as", "sa"} then


key codetusing {shift down, option down}

else if d is in {"sc", "cs"} then


key codetusing {command down, shift down}

else if d is in {"kc", "ck"} then


key codetusing {command down, control down}

else if d is in {"ks", "sk"} then


key codetusing {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


key codetusing {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


key codetusing {command down, shift down, option down}

end if

on error

repeat with k in t

if d is "" then


keystroke (k as text)

else if d is "c" then


keystroke (k as text) using {command down}

else if d is "a" then


keystrokekusing {option down}

else if d is "k" then


keystroke (k as text) using {control down}

else if d is "s" then


keystrokekusing {shift down}

else if d is in {"ac", "ca"} then


keystroke (k as text) using {command down, option down}

else if d is in {"as", "sa"} then


keystroke (k as text) using {shift down, option down}

else if d is in {"sc", "cs"} then


keystroke (k as text) using {command down, shift down}

else if d is in {"kc", "ck"} then


keystroke (k as text) using {command down, control down}

else if d is in {"ks", "sk"} then


keystroke (k as text) using {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


keystroke (k as text) using {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


keystroke (k as text) using {command down, shift down, option down}

end if

end repeat

end try

end tell

end raccourci


--=====


on save_as_html(theApp)

tell applicationtheApp to activate

tell application "System Events" to tell process theApp


keystroke "s" using {command down, shift down}

repeat until exists sheet 1 of window 1

delay 0.2

end repeat

tell sheet 1 of window 1

tell first pop up button of group 1 of group 1


click


clickmenu item 3 of menu 1

end tell


keystrokereturn

end tell

end tell

end save_as_html


--=====

(*

my get_menu_name("TextEdit", 5, 4) (* Format > FileName *)

*)

on get_menu_name(theApp, mt, mi)

tell applicationtheApp to activate

tell application "System Events" to tell process theApp to tell menu bar 1

get name of menu bar items


(*{

01 - "Apple",

02 - "TextEdit",

03 - "Fichier",

04 - "Édition",

05 - "Format",

06 - "Fenêtre",

07 - "Aide"}

*)

get name of menu bar itemmt


-- {"Format"}

tell menu bar item mt to tell menu 1

get name of menu items


(* {

01 - "Police",

02 - "Texte",

03 - missing value,

04 - "Convertir au format RTF",

05 - "Empêcher les modifications",

06 - "Adapter à la page",

07 - "Permettre la césure",

08 - missing value,

09 - "Liste…",

10 - "Tableau…"}

*)

set mName to get name of menu item mi

(*

{"Convertir au format RTF"}

or

{"Convertir au format Texte"}

*)

end tell -- menu bar item

end tell -- System Events

return mName

end get_menu_name


--=====

--[/SCRIPT]

--{code}


Yvan KOENIG (VALLAURIS, France) mercredi 1 juin 2011 21:36:54

iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.7

Please : Search for questions similar to your own before submitting them to the community


To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

Jun 2, 2011 3:16 AM in response to dieselross

Hello Yvan,


thanks for your suggestion! Since Jerrold Green1's suggestion works fine for me, i think, i'll use that in the first. But there is a certain beauty in an AppleScript solution so, as soon as i find the time, i will analyze this further and try to adapt it to my needs (opening the resulting HTML in Coda instead of Safari, removing unnecessary styling etc.). But that may take some time, especially because i've got to admit, that i don't speak any french. So i'll have to fight my way through your code where it is commented in french.

As soon as i find the time, may i contact you in doubt or to show my result?


Kind regards

dieselross

Jun 2, 2011 3:26 AM in response to dieselross

May you really open your eyes ?

This script, as all those which I post here, is commented in French and in English .

I use french words to name the variables but these ones are only kinds of avatars.

Name a variable "AlCapone" or "GWBusch" logically behave the same.


Yvan KOENIG (VALLAURIS, France) jeudi 2 juin 2011 12:23:33

iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.7

Please : Search for questions similar to your own before submitting them to the community


To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

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 do i convert a neat numbers table to a neat html table?

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