How to Hide Rows and Columns in Google Sheets Using API
Tired of messy spreadsheets? Let me show you how to programmatically hide columns and rows in Google Sheets.
I needed to hide everything except the last 14 columns automatically when generating PDFs. Doing this manually wasn't an option.
We'll use Google Sheets API to make an arbitrary call that handles the hiding. Here's how it works:
I found this initially as Python code, but converted it to JSON format that the Google Sheets API expects:
{
"requests": [
{
"updateDimensionProperties": {
"range": {
"sheetId": "YOUR_SHEET_ID",
"dimension": "COLUMNS",
"startIndex": 43,
"endIndex": 44
},
"properties": {
"hiddenByUser": true
},
"fields": "hiddenByUser"
}
}
]
}
Simply change "COLUMNS" to "ROWS" in the dimension field. The rest stays the same.
You can get fancy with this by:
Q: Will this affect the original data?
Q: Can I unhide using the same method?
Q: Does this work with multiple sheets?
You can find this solution:
If you need a custom solution, reach out via email. Happy to help make your spreadsheets more manageable!