OK,
I believe this script will work with the file you uploaded. I can't guarantee that it will work with any others.
It doesn't use Numbers, it uses AppleScript's own text processing routines and a time-honoured handler for string replacement.
There are two issues.
First, the original data uses commas as decimal separators, as is the convention in continental Europe. Writing a comma-separated file that contains non-separating commas was beyond me, so I have converted the decimal separators into points. You may find that when you open the CSV file they are silently converted back to commas, but I can't test that.
Second, it will will not work if you use it with a "genuine" Excel spreadsheet. (Although my original script will.)
Here's the script:
--begin script
--confirm existence of folder called 'dati trading csv' in downloads folder.
-- create it if it doesn't exist:
set downloads_folder to path todownloads folder
set conversion_folder to (downloads_folder as string) & "dati trading csv"
tell application "Finder" to if not (exists folder conversion_folder) then ¬
makenewfolderatdownloads_folderwith properties {name:"dati trading csv"}
--choose the original files
set file_list to (choose file of type {"org.openxmlformats.spreadsheetml.sheet", ¬
"com.microsoft.Excel.xls"} with multiple selections allowed)
repeat with each_file in file_list
--parse name of original file without extension:
tell application "System Events" to set file_name to name of each_file
set old_tids to AppleScript'stext item delimiters
set AppleScript'stext item delimiters to "."
set base_name to text item 1 of file_name
set AppleScript'stext item delimiters to old_tids
--process text for each file
set old_text to readeach_file
set nu_text to ""
set parcount to countparagraphs in old_text
repeat with x from 1 to parcount
set next_par to paragraphx of old_text--build new text string ignoring html headers etc - just including the table rows
if next_par begins with "<th>" then set nu_text to nu_text & next_par & return
if next_par contains "<td>" then set nu_text to nu_text & next_par & return
end repeat
--remove final return from string:
set nu_text to text 1 thru -2 of nu_text
--search and replace...
set nu_text to replace_chars(nu_text, ",", ".") -- replace decimal comma with decimal point
set nu_text to replace_chars(nu_text, "</td><td>", ",") -- replace html code with comma separator
set nu_text to replace_chars(nu_text, "<td>", "") --remove html code at beginning of line
set nu_text to replace_chars(nu_text, "</td>", "") --remove html code at end of line
set nu_text to replace_chars(nu_text, "</th><th>", ",") --ditto
set nu_text to replace_chars(nu_text, "<th>", "") --ditto
set nu_text to replace_chars(nu_text, "</th>", "") --ditto
--set up path and name of new .csv file:
set nu_file to conversion_folder & ":" & base_name & ".csv"
--create file if it doesn't exist, empty it if it does, write converted text to it and close it
try
set text_write to (open for accessfilenu_file with write permission)
set eoftext_writeto 0
writenu_texttotext_write
close accesstext_write
on error
close accesstext_write
end try
end repeat
-- search and replace handler from osxautomation.com (and many other sources). Used with thanks:
on replace_chars(this_text, search_string, replacement_string)
set AppleScript'stext item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript'stext item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript'stext item delimiters to ""
return this_text
end replace_chars
-- end script
I hope this works for you.
H