The objective is to remove a row in a table if it has no content
Removing the row is easy but my difficulty lays in understanding if the row is empty and then have the script identify the row is empty.
This is one of quite a number of different options attempted.
tell application “Numbers”
activate
tell table “Product List” of sheet “Summary Page” of document 1
if second row is (empty) then
remove second row
The answer may be very simple, but I am no closer today to the answer than I was yesterday. So I was really hoping for a little guidance.
There is no direct way to check that a row is empty.
Here is a script doing the job.
set rowNum to 2
tell application "Numbers"
tell document 1 to tell sheet 1 to tell table 1
set theValues to value of every cell of row rowNum
set isEmpty to true
repeat with aValue in theValues
if contents of aValue is not missing value then
set isEmpty to false
exit repeat
end if
end repeat
if isEmpty then remove row rowNum
end tell
end tell
If you must check the contents of several rows, it may be fine to use a handler :
set rowNum to 2
tell application "Numbers"
tell document 1 to tell sheet 1 to tell table 1
if my isItEmpty(value of every cell of row rowNum) then remove row rowNum
end tell
end tell
on isItEmpty(theValues)
set isEmpty to true
repeat with aValue in theValues
if contents of aValue is not missing value then
set isEmpty to false
exit repeat
end if
end repeat
return isEmpty
end isItEmpty
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) lundi 25 avril 2016 09:47:28
Thank you, at my stage of development, this would have taken days maybe weeks to solve. I thought one day on it was time to look for assistance.
It works flawlessly with and without content
Here is an alternate way which would be more efficient if you must test several rows.
set rowNum to 2
tell application "Numbers"
tell document 1 to tell sheet 1 to tell table 1
set emptyLine to {}
repeat (column count) times
set end of emptyLine to missing value
end repeat
if emptyLine = value of every cell of row rowNum then remove row rowNum
end tell
end tell
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) lundi 25 avril 2016 14:38:58