Applescript和Excel查找值并获取列字母

时间:2018-10-09 10:06:24

标签: excel applescript

是否可以从所选值中检索列字母?

让我们说我的价值在于一个特定的单元格。如何获取该单元格的列字母?

3 个答案:

答案 0 :(得分:0)

如果选择了您的单元格,则下面的脚本会为您提供行号和列号

tell application "Microsoft Excel"
    activate
    tell window 1
        set mySelection to range selection
        set myRow to first row index of mySelection
        set myCol to first column index of mySelection
        log "row=" & myRow & "   myCol=" & myCol
    end tell
end tell

一旦获得列号,就可以使用ASCII代码将其转换为字母(1 =“ A”,2 =“ B”,...)。

答案 1 :(得分:0)

这里是一种获取列字母的方法,而不必将其转换为数字。

tell application "Microsoft Excel"

    tell window 1

        -- this will return a string like "$A$1"
        set addr to get address (cell 1 of selection)

        -- with default text delimiters, words are {"$", "A", "$", "1"}
        set col to word 2 of addr

    end tell

end tell

答案 2 :(得分:0)

<块引用>

假设我的值位于特定单元格上。我怎样才能得到专栏 那个单元格的字母?

一旦你知道怎么做就很容易:

tell application "Microsoft Excel"
  set colLetter to character 2 of (get address active cell)
end tell
-->"D"