Используйте Applescript для дублирования строки n раз в Apple Numbers

После нескольких попыток с VBA и Excel для Mac вернуть синтаксическую ошибку, я прибегнул к Applescript и Numbers. Мне нужно распечатать штрих-коды для каждого предмета в нашем инвентаре; однако программное обеспечение для печати штрих-кодов распознает только строки печати и не учитывает значение ячейки инвентаря. Я пытаюсь продублировать строку n раз, где n = значение в столбце F. Кроме того, исходные данные включают только данные для столбцов A и B для первого варианта этого продукта, которые мне нужно дублировать в дополнительные строки как хорошо. Пожалуйста, посмотрите скриншоты ниже и дайте мне знать, если вы можете помочь. Благодарю вас!

Формат исходных данных:

введите здесь описание изображения

Желаемый результат:

введите здесь описание изображения


person Judson Hanna    schedule 10.03.2015    source источник


Ответы (1)


Скрипт будет различаться в зависимости от версии приложения.

Вот сценарий для Numbers Version 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 Version 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
person jackjr300    schedule 11.03.2015