如何使用 AppleScript 为一系列单元格添加边框

how to add border to a range of cell using AppleScript

我想在单元格范围内添加细边框(单元格输入因文件而异)。

我需要有人帮我解决这个问题。发现使用 AppleScript excel 更难实现自动化。

这是我的代码

set theWorkbookFile to choose file with prompt "Please select an Excel workbook file:"
tell application "Microsoft Excel"
    open theWorkbookFile
    set theWorkbook to active workbook
    tell active sheet
        tell used range
            set RowCount to count of rows
            --display dialog RowCount
            set columnCount to count of columns
            --display dialog columnCount
            
            
            repeat with theRowValue from 1 to RowCount
                repeat with theColumValue from 1 to columnCount
                    set theCell to "A" & theColumValue & ":K" & theRowValue
                    --set myRanger to theCell
                    select range theCell
                    --set mySel to selection
                    --set myRange to first item of (get areas of mySel)
                    set myBorders to {border top, border bottom, border left, border right}
                    repeat with i from 1 to 4
                        set theBorder to get border theCell which border (item i of myBorders)
                        --set weight of theBorder to border weight thin
                    end repeat
                end repeat
            end repeat
        end tell
    end tell
end tell

谢谢 阿什温

set theWorkbookFile to choose file with prompt "Please select an Excel workbook file:"

tell application "Microsoft Excel"
    open theWorkbookFile
    set myBorders to {border top, border bottom, border left, border right}
    tell active workbook to tell active sheet
        
        tell used range to set {rowsCount, columnsCount} to {count of rows, count of columns}
        
        repeat with rowValue from 1 to rowsCount
            repeat with columnValue from 1 to columnsCount
                set theCell to cell ("A" & columnValue & ":K" & rowValue)
                repeat with i from 1 to 4
                    set theBorder to get border theCell which border (item i of myBorders)
                    set weight of theBorder to border weight thin
                end repeat
            end repeat
        end repeat
        
    end tell
end tell