Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2023年9月26日火曜日

Get Hidden Rows in Google Sheets with Google Apps Script


Introduction

Google Sheets allows you to hide rows and columns. 
Hidden rows are not displayed on the sheet and cannot be edited.

To get hidden rows, you can use Google Apps Script. 
Google Apps Script provides the isRowHiddenByUser() method in the Sheet class to determine if a specified row is hidden.


Source Code


Code.gs
function getHiddenRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange("A1:A" + lastRow);
var values = range.getValues();
var hiddenRows = [];
for(var i = 0; i < values.length; i++) {
var row = i + 1
var hidden = sheet.isRowHiddenByUser(row);
if(hidden) {
hiddenRows.push(row);
}
}
Logger.log(["hiddenRows: ", hiddenRows]);
}



Reference

isRowHiddenByUser(rowPosition)

Latest post

Google Classroom API でクラスの一覧を取得したい

自分が指導・参加しているクラスの名称とIDを取得するコードを試しました 下記 Code.gs では pageSize で 100 を設定していますが 必ず 100件 返ってくるとは限らないらしいです https://developers.google.com/workspace/...