Google apps script 如何在脚本中以编程方式隐藏google电子表格中的网格线
是否有一种编程方式来控制谷歌电子表格中的隐藏/取消隐藏网格线或受保护范围?菜单-视图>网格线或保护范围中有一个选项可以执行此操作。但我想在脚本中这样做Google apps script 如何在脚本中以编程方式隐藏google电子表格中的网格线,google-apps-script,google-sheets,Google Apps Script,Google Sheets,是否有一种编程方式来控制谷歌电子表格中的隐藏/取消隐藏网格线或受保护范围?菜单-视图>网格线或保护范围中有一个选项可以执行此操作。但我想在脚本中这样做 谢谢。恐怕是个坏消息。我自己只花了一个小时寻找同样的答案,但我认为根本没有 我使用命令: sheet.getRange(1,1,maxrows,maxcolumns).setBorder(true,true,true,true,false,false,"white"); 这将更改与背景相同的白色线条颜色。然后,网格线被“隐藏”。这对我有用 有点
谢谢。恐怕是个坏消息。我自己只花了一个小时寻找同样的答案,但我认为根本没有 我使用命令:
sheet.getRange(1,1,maxrows,maxcolumns).setBorder(true,true,true,true,false,false,"white");
这将更改与背景相同的白色线条颜色。然后,网格线被“隐藏”。这对我有用 有点晚了,但这里有一个方便的代码片段,可以通过在Google Apps脚本中调用V4 API来实现这一点 为了使这一点起作用:
- 您需要在Google云控制台中为工作表的绑定Google Apps脚本项目启用Sheets v4 API,您可以从脚本编辑器中的“资源”->“云平台项目”访问该项目
- 您可能还需要启用Sheets V4 API Resources->Advanced Google services
尝试
Sheet.setHiddenGridlines(true)
。请参见此功能更好。函数hideGridline(sheet,rows,cols){for(vari=1;iThanks!这节省了我很多时间!
function test() {
var spreadsheetId = SpreadsheetApp.getActive().getId();
var sheetId = SpreadsheetApp.getActiveSheet().getSheetId();
hideGridlines(spreadsheetId, sheetId, false);
}
/**
* Hide or show gridlines
*
* @param {string} spreadsheetId - The spreadsheet to request.
* @param {number} sheetId - The ID of the sheet.
* @param {boolean} hideGridlines - True if the grid shouldn't show gridlines in the UI.
**/
function hideGridlines(spreadsheetId, sheetId, hideGridlines) {
var resource = {
"requests": [
{
"updateSheetProperties": {
"fields": "gridProperties(hideGridlines)",
"properties": {
"sheetId": sheetId,
"gridProperties": {
"hideGridlines": hideGridlines
}
}
}
}
],
"includeSpreadsheetInResponse": false,
"responseIncludeGridData": false,
}
Sheets.Spreadsheets.batchUpdate(resource, spreadsheetId)
}