在多次尝试使用 VBA 和 Excel for Mac 返回语法错误后,我求助于 Applescript 和 Numbers。我需要为库存中的每件商品打印条形码;但是,条码打印软件只识别打印行,不考虑库存单元格的值。我正在尝试将行复制 n 次,其中 n = F 列中的值。此外,源数据仅包括该产品第一个变体的 A 和 B 列的数据,我需要将其复制到其他行出色地。请查看下面的屏幕截图,如果您能提供帮助,请告诉我。谢谢!
源数据格式:
期望的输出:
在多次尝试使用 VBA 和 Excel for Mac 返回语法错误后,我求助于 Applescript 和 Numbers。我需要为库存中的每件商品打印条形码;但是,条码打印软件只识别打印行,不考虑库存单元格的值。我正在尝试将行复制 n 次,其中 n = F 列中的值。此外,源数据仅包括该产品第一个变体的 A 和 B 列的数据,我需要将其复制到其他行出色地。请查看下面的屏幕截图,如果您能提供帮助,请告诉我。谢谢!
源数据格式:
期望的输出:
该脚本将根据应用程序的版本而有所不同。
这是Numbers 版本 3.x的脚本,试试这个:
tell application "Numbers"
tell table 1 of sheet 1 of document 1
set rc to (row count) - 1
set i to 2 -- start at the second row
set {cA, cB} to {"", ""}
repeat rc times
set tValues to value of cells of row i -- get values of this row
set n_rows to item 6 of tValues -- get value in column F
if item 1 of tValues is not missing value then -- not an empty cell
set {cA, cB} to items 1 thru 2 of tValues -- get values of cell A et B
else
set item 1 of tValues to cA -- put the Title into the empty cell (A) --> new row
set item 2 of tValues to cB -- put the Vendor into the empty cell (B) --> new row
set value of cell 1 of row i to cA -- put the Title into the empty cell (A) --> original row
set value of cell 2 of row i to cB -- put the Vendor into the empty cell (B) --> original row
end if
if n_rows > 1 then
set tc to count tValues
set x to properties of row i
if background color of x is missing value then set background color of x to {0, 0, 0}
repeat (n_rows - 1) times -- add rows
set r to make new row at after row i with properties x
repeat with j from 1 to tc -- insert values
set value of cell j of r to item j of tValues
end repeat
end repeat
set i to i + n_rows -- next row, but skip these new rows
else
set i to i + 1 -- next row
end if
end repeat
end tell
end tell
--
这是Numbers 版本 2.x的脚本,试试这个:
tell application "Numbers"
tell table 1 of sheet 1 of document 1
set rc to (row count) - 1
set i to 2 -- start at the second row
set {cA, cB} to {"", ""}
repeat rc times
set tValues to value of cells of row i -- get values of this row
set n_rows to item 6 of tValues -- get value in column F
if item 1 of tValues is not 0.0 then -- 0.0 equal an empty cell for cells whose format is text
set {cA, cB} to items 1 thru 2 of tValues -- get values of cell A et B
else
set item 1 of tValues to cA -- put the Title into the empty cell (A) --> new row
set item 2 of tValues to cB -- put the Vendor into the empty cell (B) --> new row
set value of cell 1 of row i to cA -- put the Title into the empty cell (A) --> original row
set value of cell 2 of row i to cB -- put the Vendor into the empty cell (B) --> original row
end if
if n_rows > 1 then
set tc to count tValues
set {aa, bg, fs, va, ht, tco, fn, tw} to {alignment, background color, font size, vertical alignment, height, text color, font name, text wrap} of row i
try
bg
on error
set bg to missing value
end try
repeat (n_rows - 1) times -- add rows
add row below row i
set properties of row (i + 1) to {alignment:aa, background color:bg, font size:fs, vertical alignment:va, height:ht, text color:tco, font name:fn, text wrap:tw}
repeat with j from 1 to tc -- insert values
set value of cell j of row (i + 1) to item j of tValues
end repeat
end repeat
set i to i + n_rows -- next row, but skip these new rows
else
set i to i + 1 -- next row
end if
end repeat
end tell
end tell