Here's a script that should do the same thing as Wayne's. It's more modular, so it may be a littler easier to tweak if you need to do that.
To use:
In Finder create a folder to receive the configuration scripts if you don't have one already.
- Copy-paste into Script Editor (in Applications > Utilities).
- Click anywhere in the table in Numbers that contains the data.
- Click the triangle 'run' button.
- Respond to the prompt to choose a folder.
Note that this will overwrite any configuration scripts you already have in your chosen destination folder so backup first if you want to keep existing ones you have there.
SG
-- configure to match your Numbers table: put 1 for col A, 2 for col B, etc.
set {nameCol, portCol, vlanCol, descCol} to {1, 2, 3, 4}
set myFolder to choose folder with prompt "Choose folder to place configuration scripts"
-- places values from Numbers table in AppleScript list of lists (2D array)
tell application "Numbers"
tell front document to tell active sheet
tell (first table whose selection range's class is range) to ¬
set vv to rows's cells's value
end tell
end tell
-- removes any "blank rows"
set vv2 to {}
repeat with i from 2 to count vv -- the 2 assumes 1 header row
if vv's item i's item nameCol is not missing value then ¬
set vv2 to vv2 & {vv's item i}
end repeat
-- initializes variables
set {prevName, theTxt} to {"", ""}
set totalCount to count vv2
repeat with i from 1 to totalCount
-- read a row's values
tell vv2's item i
set thisName to item nameCol
set thePort to item portCol as integer
set theVLAN to item vlanCol as integer
set theDesc to item descCol
end tell
-- if not a new switch then append row block
if thisName is prevName then ¬
set theTxt to theTxt ¬
& makeRowBlock(thePort, theVLAN, theDesc)
-- if new switch and no text then make header and append row block
if thisName is not prevName and theTxt is "" then
set theTxt to makeHeader(thisName) ¬
& makeRowBlock(thePort, theVLAN, theDesc)
else -- if new switch write existing text to file, make header and append row block
if thisName is not prevName and theTxt is not "" then
writeFile(myFolder, theTxt, prevName)
set theTxt to makeHeader(thisName) ¬
& makeRowBlock(thePort, theVLAN, theDesc)
end if
end if
-- if last row write the file
if i = totalCount then writeFile(myFolder, theTxt, thisName)
set prevName to thisName
end repeat
to makeHeader(switchName)
set s to "# Script generated by AppleScript for Switch " & switchName & return
set s to s & "# on " & (current date) & return
set s to s & "!" & return & "conf t" & return
end makeHeader
to makeRowBlock(aPort, aVlan, aDescr)
set s to "!" & return
set s to s & "interface gi 1/0/" & aPort & return
set s to s & " switchport mode access" & return
set s to s & " switchport access vlan " & aVlan & return
set s to s & " description LINK TO " & aDescr & return
end makeRowBlock
to writeFile(myFolder, theText, thisSwitch)
set f to open for access (myFolder as text) & ¬
"Accessport Configuration Script " & thisSwitch & ".txt" with write permission
write theText to f
close access f
end writeFile