get sheet data without the hidden columns - google-apps-script

I am currently working on GAS project, for the moment I have a table in a sheet and the idea is that my collaborators will be able to choose the format of the table, which column and which row they want to save. I thought about using the hiding column and row features but is it possible in my apps script to get only the data which they chose to save and not the hidden data ? Thank you for you answers

Apps Script works analogously to the Sheets UI
Explanation
If from the user interface you select the desired data by "click&drag", the hidden columns located between the start and the end column will be also selected (and copied). Instead you need to select the data of interest manually with "Ctrl" and click, see here.
How to transfer this to Apps Script?
Apps Script features the method sheet.isColumnHiddenByUser(columnPosition) (and isRowHiddenByUser, isRowHiddenByFilter etc.). You can use it to select only the ranges / the values of a datarange in columns and rows that are not hidden.
This implies the implementation of loops and conditions statements, so is not necessary an elegant solution.

Related

How do I lock a cell's copied value determined by a formula and prevent it from updating when the referenced cell in formula does?

the sheet I'm working on generates a request number on the very first submission a user makes of a google form based off of information the user inputted in the form and a timestamp. Now, because I need for the user to be able to edit their response later which causes the form to be re-submitted, I want the request number not to be regenerated, and to stay the same as when it was initially generated. Is there any way to prevent a cell from changing from its initial value when it contains a formula that references a cell that updates?
Here is the formula contained in the cell I don't want to update with alongside its references:
=ARRAYFORMULA(ARRAY_CONSTRAIN(if(ROW(A:A)=1, "Request ID", if(D1:D="", "",C1:C&"-"&G1:G&"-"&N1:N)), MAX(if(D1:D="",0,ROW(D1:D)))-ROW()+1,1))
The formula appends different values received from the form together to create a request number (formatted as essentially C1:C-G1:G-N1:N, timestamp-System-initials) and the arrayformula and constraint ensures the formula is copied to each row in the sheet that contains a form response so far. I want this request number to stay the same as it's initial value, even as columns C, G, and N change.
Edit: Not really sure how I can provide a search history on what I've tried so far because I've been searching for anything I can to fix this problem because it's important. I've looked into indirect referencing, absolute references, considered using PropertiesService (Google Apps Script) in order to store whether the request number has been initiated before and got stuck there, considered copying the value into another column to store it but again the autoupdating feature that accompanies linking cells of course still remains an issue. I'm stuck on what kind of function/workaround I could use to achieve this. Look forward to your thoughts. I've also tried a number of other strategies as well.
Since formulas recalculate each time the spreadsheet is recalculated using a formula is not the right way to keep the original value on the current spreadsheet version. The way to achieve this is by using a script to log those values.
There are already a lot of questions about using a script to log values from one sheet to another. Here are few examples
How to Get (& Set) cell values from one sheet to another in Google Sheets?
I want to write a script to read and log values of a specific row and copy them to a new sheet

Custom query in google spreadsheet using script

I want to get values from selected columns of a spreadsheet.
Of course, the spreadsheet query function can cover that well. But query an external sheet keeps showing the Import Range (REF#) Internal Error (my guess is due to heavy traffic from the source sheet), and my target sheet have to be in working order all the time, since it is kind of like a hub for the candidates we recruit.
So my solution using script is getting the values of each column, and write those values into each columns of the target sheet. Essentially, I have to run a lot of similar loops in my script.
I'm wondering if there is a more productive and dynamic way to get the desired columns from another spreadsheet (kinda like query in scripted form)?

SELECT and COPY row to another SHEET in Google Spreadsheets

I'm currently working on a Spreadsheet, and I'm up to the point of creating either a button or checkbox to SELECT and COPY a row to another sheet as part of an efficient archiving system. For e.g. the user will select their row, click the button and the row will be copied in the mentioned sheet. I'm still quite new to scripting in Google Spreadsheets as a whole. I personally wanted to head into the direction of using a button, but I'm open to suggestions.
Thank you all!
I think that works (you will be assigning a script/function to an image you upload, and then in the function use .getRow() on the active cell). Here is some advice that could save you some time. For your use case, instead of using a button, consider using the QUERY command:
You have a table in "sheet1" with some columns:
In that table you have an IMPORT column. You can use data validation on that column so that it is a Yes/No dropdown as well.
In a separate sheet, you write this which picks out all the rows with "Y":
=query(sheet1!A2:D1000,"select A,B,C where D='Y'",0)
And that will output this (minus the headings, which you can customize based on the last argument of the QUERY command):

How to add a button in Google Sheets that Automatically Adds Columns and formulas

I would like to add a script to a button I created in Google Sheets. I would like the button to add a new column before my "Month Loss" column. I would like the new column to copy the formulas and formatting of the column to the left.
This will provide an easy way to track my body measurements and help to determine calculate my body fat percentage.
Here is a link to my sheet: https://docs.google.com/spreadsheets/d/1DP0SQpU16YEfPWoE8IRknoqQWu0wrFagzhLflVOkn8M/edit?usp=sharing
A Pivot Table has been created though script. if you try to programmatically update the range, there is no way either because named ranges need to be deleted then re-added which causes on the pivot.
if you are adding the new row by script, do not append it to the end. instead keep a fake row at the end and insert the new row just before it. your range (named or not) will update.
Even for the google forms case you might get it to work by pre-adding all blank rows to the response sheet and make the named range include the blank ones too.
Found this Stack Overflow ticket discuss about Pivot Table, you may also check the solution offered by the community: Google Spreadsheet Pivot Table Range Update Using Scripts

Is there some way to populate all the cells from 1 function call instead of 1 call for each cell?

Here is my issue. I have a spreadsheet with multiple sheets, and each sheet has about 300-500 rows. I am using ScriptDb to store the data for each sheet.
What I am currently doing is calling a custom function in 300-500 cells in each sheet to populate certain cells with data, and what happens is that some will populate and the rest will error out saying i've queried the database too many times in a short period. Obviously having to query the database for each cell isn't the best solution.
How would I go about querying all the data for the current sheet and then having that data available to grab for each cell. What I've read is that you can't really have "global" variables in GAS, but have to use things such as CacheService or ScriptDB, which is what i'm trying to do. I'm just querying it too much.
Is there some way to populate all the cells from 1 function call instead of 1 call for each cell? What am I missing or what other solutions are there?
Just realized a similar question was asked earlier today: Google Spreadsheet Script invoked too many times per second for this Google user account
Yes its possible. Simply return an array from your function. It will work like an arrayformula.
Of course your cells would need to be contiguous.