Applescript Excel单元格搜索和替换其他单元格

时间:2014-10-09 09:11:34

标签: excel applescript applescript-excel

我是苹果脚本的新用户,希望得到一些帮助。

我正在尝试使用Applescript和Excel来自动化我的工作,以便它可以更快。

在浏览了一个带有重复数据删除记录的AppleScript后,我希望能够检查一个列(A列)是否有一个数字值大于100.如果是,我想要另一列(B列)与“已注册”文本粘贴的同一行。

接下来我想自动过滤并删除列B中有“Normal”文本的任何行

提前感谢您的帮助。

以下是我用于删除列和推断记录的代码。

截至2014年10月11日的更新问题 1)我需要选择基于文本中最后一列的单元格中的行。只要感觉不是SG。应该选择该行 2)我需要能够复制该行并将其移动到最后一行(这是一个艰难的行,因为我从这个逻辑看到一个永无止境的循环 - 结束重复会停止这个循环吗?) 3)我需要从列表中删除所有空格。 4)我需要从上到下按顺序完成1和2,这样它们的ID就不会混乱。

2014年10月11日以ShooTerko的剧本

更新
tell application "Finder"
activate
open document file "orders.csv" of folder "Input" of folder "Automation" of folder "AAS Orders" of folder "A A Selections 1st June" of folder "Adlina A. Pte Ltd(NEW)" of folder "Fizzy Pop Pte Ltd" of folder "Dropbox (Fizzy Pop)" of folder "zayedtalib" of folder "Users" of startup disk

tell application "Microsoft Excel"
    tell active sheet of active workbook
        set myColumn to range "B:K"
        delete myColumn
        set myColumn to range "C:D"
        delete myColumn
        set myColumn to range "D:V"
        delete myColumn
        set myColumn to range "F:G"
        delete myColumn
        set myColumn to range "K:AA"
        delete myColumn
    end tell
end tell
tell application "Microsoft Excel"
    set maxRow to count of rows of used range of active sheet
    repeat with currentRow from maxRow to 2 by -1

        set currVal to (value of row currentRow of column 1 of active sheet)

        set nextVal to (value of row (currentRow - 1) of column 1 of active sheet)

        if currVal = nextVal then
            delete range (row currentRow) of active sheet
        end if
    end repeat
end tell
tell application "Microsoft Excel"
    autofilter range range "C:C" field "1" criteria1 "Normal >14days"
end tell
tell application "Microsoft Excel"
    if exists active sheet then
        set usedRows to every row of (used range of active sheet) whose value is not missing value

        -- Walk through the used rows
        -- Set values of column B to "Registered" if value of column A is greater than 100
        repeat with aRow in usedRows
            if (value of row (first row index of aRow) of column ((first column index of aRow) + 1) is greater than 100) then
                set value of row (first row index of aRow) of column ((first column index of aRow) + 2) to "Registered"
            end if
        end repeat

        -- Loop from last rows to first rows to easily delete rows
        -- Delete all rows containing "Normal" in column B
        repeat with aRow in (reverse of usedRows)
            if (value of row (first row index of aRow) of column ((first column index of aRow) + 1) = "Normal") then
                delete aRow
            end if
        end repeat
    end if
end tell
tell application "Microsoft Excel"
    autofilter range range "C:C" field "1" criteria1 "Registered"
end tell

告诉

1 个答案:

答案 0 :(得分:0)

我尝试了这个,它的工作原理如下:

tell application "Microsoft Excel"
    if exists active sheet then
        set usedRows to every row of (used range of active sheet) whose value is not missing value

        -- Walk through the used rows
        -- Set values of column B to "Registered" if value of column A is greater than 100
        repeat with aRow in usedRows
            if (value of row (first row index of aRow) of column (first column index of aRow) is greater than 100) then
                set value of row (first row index of aRow) of column ((first column index of aRow) + 1) to "Registered"
            end if
        end repeat

        -- Loop from last rows to first rows to easily delete rows
        -- Delete all rows containing "Normal" in column B
        repeat with aRow in (reverse of usedRows)
            if (value of row (first row index of aRow) of column ((first column index of aRow) + 1) = "Normal") then
                delete aRow
            end if
        end repeat
    end if
end tell