Google scripts unhideRows not working - google-apps-script

I have a script for Google Sheets I am working on. I realize there are better ways to do what I am attempting (cough html/database cough), but I am required to make this spreadsheet work.
In short, I am trying to hide and unhide rows dynamically. There does not appear to be a way to get filters to update without redoing them, so I am attempting to use hideRows to hide them and unhideRows to reveal them as needed.
The hideRows command works below. The unhideRows command does not. At this time, they are literally this close together in the code. Originally, I was hiding on one sheet and unhiding on another, but set up like this to troubleshoot. There is no filtering on this sheet (because it didn't work, I turned it off). I tried setting the value in unhideRows directly to the value tested instead of a variable.
The row in question hides, but does not unhide.
I tried unhiding a different row just in case google was fumbling with hide this, unhide it back to back. I am not getting unhide to work.
{ //thisRow = the row number of a range, in this case 2 if output to screen
pImages.hideRows(thisRow);
pImages.unhideRows(thisRow);
}

Apparently, the answer is not to unhideRows() which is the one the documents alluded to, but showRows () which does make more sense in everyday language. Thanks again to Mr.Houdini on the Google forums.

Related

Why do my Google Sheet custom functions require this weird workaround?

I’m creating custom functions in Google Sheets using their google apps script language. I’ve done my development on a laptop and it seems to work correctly.
However, when I open the sheet on my mobile device (iOS), the cell output for my custom functions get stuck at “Loading…” forever and never load. But I discovered this weird workaround, but I don’t know why it works or if there’s a better way: if I make a small, trivial change to one of the input cells, then close the sheet and reopen, the sheet will be correctly updated.
Note that if I just make a change to a cell, or add/delete a column etc, without closing and reopening, to force an update, it will still get stuck at “Loading…”.
Also note that if I close and reopen the sheet without making any change, it will still get stuck.
Any ideas of what’s going on here, and if there’s a better way to get my custom functions to correctly update without timing out?
I searched online for solutions, couldn’t find anything.
Update: Example sheet located at this link:
https://docs.google.com/spreadsheets/d/12nm9EwuzqaN0jYUv75CquMhrcUGlVsmEPFoWd92yuWo/edit
Look at the “SeasonTest” tab, cell AS5. On a mobile device it always shows “Loading…” (unless the above workaround is used), but works fine on a desktop

Is there any way to make it so that a cell can only be changed once in Google Sheets?

I have a Sheet which I would like to use as a simultaneous sign up for many people for timeslots for an event. We have noticed that what can happen is users erasing each other's entries in the sheet. Ideally we would like to make it so once someones name is entered for a timeslot it cannot be removed by other users.
I've tried to use data validation to reject certain criteria, but I've only managed to get it to reject a cell changing from blank to a non-blank value. Which I achieved with the following:enter image description here. But I'd like the opposite behaviour, with some additional functionality
Changing the formula to NOT(ISBLANK(B2)) doesn't seem to put any restriction on the cell at all as hitting backspace or delete on cell seems to clear the contents without ever considering that an input to check. Changing the value never causes the cell to go blank so it doesn't seem to affect changing either. I'm really at a loss as to how to do this and any help is appreciated. I'm open to solutions which use VBA or other programming languages to get the desired result as well.

Google Sheets - Track Current Cell Selection?

How to Get the currently selected cell/range? was asked 3.5 years ago, but I'm hoping maybe some progress was made since then.
I'd like to make an interactive spreadsheet where there's a boolean grid that will display more information about the status of the currently selected cell in a static location, allowing users to quickly navigate using the arrow keys.
Referencing the previous instance of this question, I tried using the custom function below to get the cell address, although this isn't very dynamic.
function currentCell() {
return SpreadsheetApp.getActive().getActiveRange().getA1Notation();
}
When testing, this function returns the address of the cell the function is called from. I've tried pressing F5 while highlighting another cell and nothing happened. I've also dragged the formula across a selection and each cell only contains its own address (according to the documentation, it should contain the range).
I've also read Henrique's post on caching from 2012, and while I don't completely understand it, I get that we could not get scripts which update without edits being made or manual formula updates.
I would ideally like for the current cell to be tracked without any extra prompts from the user besides arrow key navigation or clicking to select a cell, but if pressing a non-altering key (like Enter) would allow for tracking, that would be fine. I also only need the selected cell, rather than a range, if that makes things easier.
Explicit Question: Is it possible to track the position of the currently selected cell in Google Sheets and store that position in a separate cell? If not, is there a way to do this without altering cell values?
EDIT: Adding an example for clarity. In this conceptual example, A2 =currentCell() as described above. If I were to hit the right arrow key, A2 would update to display I4, since it is now the current selection.
EDIT2: Jason Allshorn's response to Google app script monitor spreadsheet selected ranges appears to give a way of displaying the current selection (range) on the HTML input text. I'd like to do this, but store the value in a static cell on the sheet rather than input text. I'm new to scripting in Sheets and really only know what I've found for resolving this issue, so if I'm overlooking something, please let me know. I did look at Jason's example sheet and it wasn't clear to me what was actually happening there.
You will have to apply the technique suggested on How do I make a Sidebar display values from cells?. This consist on using using client-side code to constantly pulling values from the spreadsheet and then do the corresponding task.
One approach is to use a side-panel with an input field to set the cells to be tracked and another input field to set the destination cell.
You will have to use the onSelectionChange event in the app script to capture any selection change and then get the range name and put it in desired cell.
Something like the below:
function onSelectionChange(e) {
const range = e.range;
//Return in case of multi cell selection
if(range.getNumRows() !== 1 || range.getNumColumns() !== 1) return;
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A2").setValue(range.getA1Notation());
}
You can see the official documentation here

How to call a script in Google Spreadsheet above a frozen row?

Above a frozen row I want to put an image that is linked to a script; e.g. click the image and a script runs.
I can insert an image and add a script to it, problem: can only be
done under frozen row.
I can insert an image using =image("imageurl";2), I can even put a
hyperlink to this =hyperlink("url"; image("imageurl";2)) and this
works nicely but I can't call a script.
Any ideas on how to solve this?
How do you add UI inside cells in a google spreadsheet using app script? ... shows how to insert a drawing and link it to a script. Unfortunately, as you've found, floating images are not allowed in frozen rows or columns, so that technique breaks down if you must freeze rows. A quick search on the interwebs will show that this has been a long-term complaint about Google Sheets. (For instance.)
There are options, none of them ideal:
Use a custom menu function instead. That means users need to hunt a bit to find the menu option to kick your script, but it does stay in view no matter where they are.
Use the hyperlink & image work-around you've described, but use a published script url as the target. That will allow you to run a google apps script, indirectly.
Use a sidebar. OK, this isn't actually supported in Sheets yet - visit Issue 3162 and star it for updates.

Linking one cell to another in a spreadsheet

I have a dynamically generated spreadsheet. I would like to be able to allow the viewer to go to a different sheet/cell when a cell is clicked on. I'm having trouble figuring out a good way to do this.
Going to the new cell is fairly easy: Spreadhseet.setActiveSheet()/Spreadsheet.setActiveRange() work fine. My thought was to encode the link destination in the contents of the source cell, and then write a script to "follow" the link.
I tried using images or drawings. But there were two problems with this: while images can be inserted programmatically, I did not see a way to programmatically associate a script with them. And the called script does not have an associated event tied to it, so there is no way to see what cell the user clicked (clicking an image does not set the active cell).
I thought about using onEdit(). This almost works, but onEdit is only triggered on changes (not selection) so the user actually has to modify the cell in order to "link". When testing I tended to zap the contents of the cell by accident with onEdit.
I tried making a menu item, and in the menu's script get the active cell's contents to determine where to go to. This worked but was a bit more difficult for the user than I was hoping for.
I was hoping someone would have a creative solution to this problem.
Thanks!
From what you are describing the drawing or image insertion should work since it has exactly the same functionality as the menu item. You can assign a script to it just like in a menu.