在 Google Apps 脚本中设置单元格边框宽度
Setting cell border width in Google Apps Script
虽然 GoogleSpreadsheet 中的单元格边框可以手动设置为 6 种不同的样式(点线、虚线、实线(1px 宽度)、实线(2px 宽度)、实线(3px 宽度)和双线),但目前的版本似乎API 的选项仅限于 BorderStyle 的 DOTTED、DASHED 和 SOLID 选项。后者的宽度为 1px。
有没有一种方法可以让我设置宽度为 2px 的边框,方法是选择不在 BorderStyle 枚举中的其他 3 种样式之一,或者通过任何变通方法设置边框宽度?
从 2017 年 2 月开始,多个边框厚度选项似乎是一个非常新的功能,所以我认为它没有进入应用程序脚本的枚举选项。
这应该有效
function borders() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Line 1").getRange("E21:F26").setBorder(true, true, true, true, true, true, 'black', SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}
当然 sheet 和范围只是我用来测试的,应该适用于任何 range/sheet。
Here's the documentation for the border styles and here is the documentation for .setBorder
虽然 GoogleSpreadsheet 中的单元格边框可以手动设置为 6 种不同的样式(点线、虚线、实线(1px 宽度)、实线(2px 宽度)、实线(3px 宽度)和双线),但目前的版本似乎API 的选项仅限于 BorderStyle 的 DOTTED、DASHED 和 SOLID 选项。后者的宽度为 1px。
有没有一种方法可以让我设置宽度为 2px 的边框,方法是选择不在 BorderStyle 枚举中的其他 3 种样式之一,或者通过任何变通方法设置边框宽度?
从 2017 年 2 月开始,多个边框厚度选项似乎是一个非常新的功能,所以我认为它没有进入应用程序脚本的枚举选项。
这应该有效
function borders() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Line 1").getRange("E21:F26").setBorder(true, true, true, true, true, true, 'black', SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}
当然 sheet 和范围只是我用来测试的,应该适用于任何 range/sheet。
Here's the documentation for the border styles and here is the documentation for .setBorder