【问题标题】:Remove cell borders删除单元格边框
【发布时间】:2015-11-23 14:41:50
【问题描述】:

我在使用 Applescript 删除数据表中的单元格边框时遇到问题。 我从一个包含 C15:K31 中数据的电子表格开始。每个单元格周围都有一个边框。我要做的就是在索引 4(D 列)处插入一列,然后将 D 列中的每个单元格设置为没有任何边框。我包含了一个重复来查看 D 列中的每个单元格,但理想情况下,我会简单地一次性删除所有格式,而不需要重复。

有什么想法吗?我的代码如下:

告诉应用程序“Microsoft Excel”

activate workbook
try
    set maxCount to count of sheets of active workbook
    set sheetCounter to 1
    repeat maxCount times
        activate object worksheet sheetCounter
        set theWorksheetName to name of worksheet sheetCounter of active workbook
        if theWorksheetName contains "gap" then
                insert into range column 4 of active sheet
                set column width of column 4 of active sheet to 7.5
                set color index of interior object of column 4 to 0

                set startFormatHere to range "D1" of active sheet
                set nextRow to 1
                repeat 20 times
                    set formatCell to (get offset startFormatHere row offset nextRow)
                    set formatHere to (get address of formatCell)
                    set cellRange to range formatHere

--以下尝试均无法去除边界线

                    --clear contents range "D2" of active sheet of active workbook 
                    --tell border object of range "D2"
                    --set {line style, line weight, weight, visible} to {None, 0, 0, false}
                    --end tell

                    --set border of range "D2" to false
                    --set weight of (get border of cellRange which border edge bottom) to None
                    --set line style of border object of range "D2" to line style none                  

                    --set line weight of cellRange to 0

                    set nextRow to nextRow + 1
                end repeat
            end repeat
            set sheetCounter to sheetCounter + 1
        else
            set sheetCounter to sheetCounter + 1
        end if
    end repeat
end try

说完

【问题讨论】:

    标签: excel applescript


    【解决方案1】:

    你需要get border命令-->get border (a range) which border (an enumeration),可以是以下之一:

    内侧水平、内侧垂直、对角向下、对角向上、边缘底部、‌边缘左、‌边缘右、‌边缘顶部、边框底部、边框左、‌边框右、‌边框顶部


    tell application "Microsoft Excel"
        activate workbook
        set maxCount to count of sheets of active workbook
        repeat with sheetCounter from 1 to maxCount
            activate object worksheet sheetCounter
            set theWorksheetName to name of worksheet sheetCounter of active workbook
            if theWorksheetName contains "gap" then
                insert into range column 4 of active sheet
                set column width of column 4 of active sheet to 7.5
                set color index of interior object of column 4 to 0
    
                set myRange to range "D1:D20" of active sheet
                set myBorders to {border top, border bottom, border left, border right}
                repeat with i from 1 to 4
                    set theBorder to get border myRange which border (item i of myBorders)
                    set line style of theBorder to line style none
                end repeat
            end if
        end repeat
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 2013-08-08
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多