简体   繁体   English

如何使用 Google Apps 脚本边界数据?

[英]How to border data using a Google Apps script?

I have a list that repeats in the same order and I have to format it manually by pressing Alt+H+B+A我有一个以相同顺序重复的列表,我必须按 Alt+H+B+A 手动格式化它

Can I do it through a script?我可以通过脚本来完成吗?

在此处输入图片说明

First you need to choose your data range.首先,您需要选择数据范围。 Then set border to selected data range.然后将边框设置为选定的数据范围。

Here's document from developers.google.这是来自developers.google 的文档。

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var cell = sheet.getRange("B2");
// Sets borders on the top and bottom, but leaves the left and right unchanged
// Also sets the color to "red", and the border to "DASHED".
cell.setBorder(true, null, true, null, false, false, "red", SpreadsheetApp.BorderStyle.DASHED);

Here's the link for your reference.这是供您参考的链接。 https://developers.google.com/apps-script/reference/spreadsheet/range#setBorder(Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,String,BorderStyle) https://developers.google.com/apps-script/reference/spreadsheet/range#setBorder(Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,String,BorderStyle)

Here's the function can make what you need.这里的功能可以满足您的需求。

function set_databorder() {
  const ss = SpreadsheetApp.getActiveSheet();
  for(i=1;i<=120;i=i+13){
      for(j=1;j<=30;j=j+3){
        ss.getRange(i,j,13,3).setBorder(true, true, true, true, false, false, "green", SpreadsheetApp.BorderStyle.DOUBLE);
      }
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM