-1

在带有 AppleScript 的 Excel 中,我有 10k 行和大约 200 列 XLSX。我可以通过以下方式获得已使用列的总数:

set tCols to columns of used range of activeSheet

在 200 多列中,我只需要大约 10 列,所以我将它们添加到这样的记录中:

set nRec to {"Mon","Tues","Wed"}

我可以通过以下方式循环列:

repeat with i in tCols
    ## further code
end repeat

但是当我尝试评估当前列的第 1 行是什么时,它会变得很重,因为它正在评估该列中的所有内容。当我使用以下测试转储列的属性时:

return i ## gets base column properties
return cells of i ## target cell scope
return columns of i ## target's column scope
return value of rows of i 

每个命令都在评估该列的全部内容。AppleScript 和 Excel 中是否有办法仅获取列的字母数字值 ( A, B, C, D),以便我可以根据是否包含在我的记录中来编写条件来确定是否应该删除整个列?

我对文档的理解是,如果我有列值,我可以使用类似A1. 当我在 SO 和 MacScripter 上搜索时,我只能找到将整个专栏纳入评估的解决方案。

4

1 回答 1

1

这提供了第 2 行包含目标值的列的列表。例如 40 列的数据,我在前 21 列的第 2 行填充了“周一”、“周二”等(每天 3 次,其余 19 列留空)。结果是一个包含每天三个匹配列号的列表。希望我理解你的目标。

tell application "Microsoft Excel"
    tell active sheet
        
        set uRange to used range
        set tRange to range "2:2" -- row 2
        
        -- Intersect to get second row of used range
        set iSect to intersect range1 range of uRange range2 range of tRange
        
        set valueList to value of cells of iSect as list --> list of every row 2 value
        
        -- index of cells which match desired value
        set matchList to {}
        set goalList to {"Mon", "Tue", "Wed"}
        repeat with a from 1 to count of valueList
            
            if item a of valueList is in goalList then
                copy a to end of matchList
            end if
        end repeat
        
    end tell
end tell
matchList --> {1, 2, 3, 8, 9, 10, 15, 16, 17}
于 2021-01-08T07:35:03.480 回答