![](/img/trans.png)
[英]Why is batch operating in Google Sheets App Script such as "setFontWeights(Array)" function not working?
[英]How to group data into tables in Google Sheets App Script using Batch Operating technique with Array to improve execution time?
如google app脚本文档中所述,为了提高性能,建议使用数组进行批量操作,这样可以在setValues(Array)、setFontWeights(Array)、setHorizontalAlignments的帮助下显着减少数据读写的时间(数组)函数。
我想知道如何使用这种技术设置边框,因为没有 setBorders(Array) 函数。
如果你想快速设置边框,启用 sheet api 服务并适配以下脚本(这是一个例子)
function setBorderCells() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const sh = ss.getActiveSheet()
bordersUpdating(ss.getId(), sh.getSheetId(), 2, 6, 7, 8)
}
function bordersUpdating(id, gid, startRow, endRow, startColumn, endColumn) {
const resource = {
"requests": [
{
"updateBorders": {
"range": {
"sheetId": gid,
"startRowIndex": +startRow - 1,
"endRowIndex": +endRow,
"startColumnIndex": +startColumn - 1,
"endColumnIndex": +endColumn
},
"top": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
"bottom": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
"left": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
"right": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
"innerHorizontal": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
"innerVertical": {
"style": "SOLID",
"width": 1,
"color": {
"blue": 1.0
},
},
}
}
]
}
Sheets.Spreadsheets.batchUpdate(resource, id);
}
您可以简单地将 setBorder(和其他函数)应用于一个范围:
SpreadsheetApp.getActive().getSheetByName("Log")
.getRange(1,1,5,5)
.setBorder(true,true,true,true,true,true,
"green",SpreadsheetApp.BorderStyle.DASHED)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.