Google Sheets - 2-way sync with consolidated data from multiple files - google-apps-script

High Level:
I am looking to consolidate multiple google sheets into a master Google sheet, where changes made on either the master or the individual sheets is synced.
Details:
We have multiple google sheets files that detail product that has been ordered for a specific job. I would like to consolidate the data in these sheets into one master, so that our shipping/receiving department can mark items as delivered in the master, and that change is reflected in the individual order sheets. I want to avoid putting individual file URL's within the script, because order sheets are archived once completed, and new order sheets are created.
I picture a script that pulls all of the order sheet URLs from the folder they're housed in, and then populates the data from those sheets, and sync's each line item to their respective origin.
I have been able to create a script that populates all of the file names and URL's into a spreadsheet, but that is as far as I have gotten.

Related

Google Sheets Update Filter data range when new rows aded

I have a Google Sheets spreadsheet with several tabs. Data is written to the 'tracker' tab constantly by a script which is writing information from incoming files. So new rows are constantly being added.
The tracker tab has a number of 'filter views' built using the UI. The data range that these filter views point to does not update when new rows are added.
I have seen some scripts which seem to be able to update the range if usng the Google Sheets API. However, I need something that runs within Google Apps Script itself..
Can anyone help?
The answer was to add the Google Sheets API via the add Services menu.

Google Sheets Script To Check Changes From One Sheet File To Update Another Sheet URL

Apologies if something like this has already been asked, I have little to no experience with this.
Is there script that can check a Google Sheets workbook for edits to then affect a different Sheets workbook. I have found something along these lines but it always references the same workbook and moves the entire row.
I have a spreadsheet that contains multiple lists of users (Sample Move) and another staff member has a sheet containing activity status and other details (Sample Edit). When a user is placed on the Sample Edit spreadsheet, they would then need to be moved from their respective Active list and moved to the corresponding Inactive list. Users would not need to be automatically added back to the active list once they return, that would be a manual process.
Link to example Sample Move: https://docs.google.com/spreadsheets/d/1q3yRMa5sum8dHLyw_2ppLaWBUEoj_Gl6F_btWIiqsfw/edit?usp=sharing
Link to example Sample Edit: https://docs.google.com/spreadsheets/d/1IZzoJQkFsavgnjkwz1GkuwDj-m6kG-CYQfLKx2EmPSI/edit?usp=sharing

How to list or index all sheets/tabs in Google Sheets with formulas (no scripts)

I have a Google Sheets documents with several tabs that every so often get their positions rearranged or where new tabs get added. Is there a way to create an index of tabs with formulas (no scripts) on a column? Due to work constraints (safety and connection policies and guidelines for the multiple users), scripts can't be implemented.
I'm adding the links for scripting solution for anyone that might be looking for this and can use them:
Is there a Google Sheets formula to put the name of the sheet into a cell?
How do I dynamically reference multiple sheets on Google SpreadSheets?

Google Sheets Mulitple Publish to Web

I have a Google Sheet with 50+ rows of data. I am then using the Autocrat add-on to create 50 separate Google Sheets with the individual data. Autocrat produces a list of URLs to each document.
I would like to use these URLs to then publish each one to the web in bulk, and have the published URLs put back into this spreadsheet next to the current data (URL with a corresponding data row).
Is this possible?

Google Sheets Sheet Protection

I have a spreadsheet with multiple sheets within. I have this spreadsheet shared with multiple users, and I need to protect the sheets so that certain users can only view and edit one sheet of this spreadsheet. As follows:
User 1 (one location manager) needs to view and edit Sheet 1 (that
location's payroll)
User 2 (another location manager) needs to view and edit Sheet 2
(that location's payroll), but NOT Sheet 1
User 3 (district manager) needs to view and edit both Sheet 1 AND
Sheet 2, but NOT Sheets 3 & 4.
User 4 (regional manager) needs to be able to view and edit Sheets 1,
2, 3, and 4.
Google Sheets only offers protection against editing, but I am wondering if there is any third-party app, script, or workaround that allows this functionality of protection against viewing?
Short answer = No. If you can't find this method via an API or script, there's no way a third party will offer it (They have access to the same APIs we do).
Slightly longer solution: You can create one master spreadsheet that contains all this data, then have 4 other spreadsheets (One for each user) that pulls the data from the correct sheet(s) into their personal spreadsheet.
For the slightly longer solution, you're looking at an 'onOpen' trigger in that specific users spreadsheet, so when they open the spreadsheet, it copies the right sheets from the Master spreadsheet to the spreadsheet they've just opened. Methods such as 'openByID' (To allow you to get another spreadsheet) and 'copyTo' (to copy another spreadsheets sheet to the current spreadsheet) are your friend here.
A very, very simple version of this might be:
var ss = SpreadsheetApp.openById("ID-FOR-MASTER-SHEET");
var sheet = ss.getSheets()
var destination = SpreadsheetApp.openById("ID-FOR-USERS-SHEET");
sheet[0].copyTo(destination);
Otherwise, if you have access to a Google Spreadsheet, you can always view all sheets within.
Idea
Split the tabs into separate sheets. Create a folder and place all documents in it. Share each sheet only with the owner that needs it and then share the folder with the regional manager.
Bonus
Try importrange command.
You can do: =IMPORTRANGE(A1,A2)
A1 = Sheet URL
A2 = Tab!Range ie Store1!A1:Q500
Use it to create a master sheet that pulls data from all of the individual stores, that can give the regional manger an easy snapshot. You can even mirror the original tab structure.
Comment on Separate Workbook architecture and ImportRange
I would caution against splitting the application into separate workbooks. Use of the ImportRange() requires you set sharing permissions to "Anyone with link" rather than the more secure "Only specific users".
I just re-architected an expense authorization application away from the separate (six) workbooks to a single master workbook because of this security issue.
Alternatives: Content Service
In my application, I use Content Service to do edit operations that only the owner of the database can do. The authorized users can only edit specific ranges in specific sheets. Then to do the magic, they execute macros using the content service that runs as the database owner.
Controlling Viewing
Conceivably you could program the workbook to hide sheets dependent on who the user is. This requires they authenticate themselves (you cannot do this in onOpen() for example. The problem with this is when you get collaborators viewing the workbook simultaneously. It would be interesting to see how Sheets would handle concurrent views of the same document. Knowing Google, I bet it would work.