【问题标题】:How to hide grid lines in google spreadsheet programmatically in a script如何在脚本中以编程方式隐藏谷歌电子表格中的网格线
【发布时间】:2012-11-06 12:09:15
【问题描述】:

是否有编程方式来控制隐藏/取消隐藏 Google 电子表格中的网格线或受保护范围?菜单中有一个选项 - 视图 > 网格线或受保护的范围来执行此操作。但我想在脚本中执行此操作。

谢谢。

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    【讨论】:

    • 毫无疑问是最佳答案。简单,一行代码,非常有效!它完美地工作! @pomo
    【解决方案2】:

    有点晚了,但这里有一个方便的 sn-p 可以通过从 Google Apps 脚本中调用 V4 API 来完成此操作。

    为此工作:

    • 您需要在 Google Cloud Console 中为 Sheet 绑定的 Google Apps 脚本项目启用 Sheets v4 API,您可以在脚本编辑器中通过 Resources->Cloud Platform 项目访问该项目。 .

    • 您可能还需要启用 Sheets V4 API 资源->高级 Google 服务...

    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)  
    }
    

    【讨论】:

    • 谢谢!这为我节省了很多时间!
    【解决方案3】:

    我使用命令:

    sheet.getRange(1,1,maxrows,maxcolumns).setBorder(true,true,true,true,false,false,"white");
    

    这会将线条颜色更改为白色,与背景相同。然后,网格线被“隐藏”。这对我有用。

    【讨论】:

    • 这个功能比较好。函数 hideGridline(sheet,rows,cols){ for (var i=1; i
    【解决方案4】:

    恐怕是个坏消息。我自己只花了一个小时寻找相同的答案,我认为没有!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多