I have a recurring process where I have a zip file with 4 CSVs that I want to add to a google sheet (new or existing). Is there a way to automate this?
It's just a one time import, not live data.
To do this manually, use File > Import four times and choose the Append to current sheet option each time.
To automate this with a Google Sheet formula, the data must be in .csv files rather than a .zip file, and those files must be reachable through the web without authentication.
If you can automate the unzip process and place the files in the cloud someplace, say a Dropbox folder, so that the file URLs are always the same, you can use importdata() like this to concatenate the files:
={
importdata("...url1.csv");
importdata("...url2.csv");
importdata("...url3.csv");
importdata("...url3.csv")
}
To automate this with Apps Script, use an installable trigger to run a function that uses UrlFetchApp, Utilities.gunzip and Utilities.parseCsv() to get the data, Array.concat() to merge the files, and Range.setValues() to write the results in the spreadsheet.
To reference a cell or range of cells in another worksheet in the same workbook, put the worksheet name followed by an exclamation mark (!) before the cell address.
In other words, in an Excel reference to another worksheet, you use the following format:
Reference to an individual cell:
Sheet_name!Cell_address
For example, to refer to cell A1 in Sheet2, you type Sheet2!A1.
Reference to a range of cells:
Sheet_name!First_cell:Last_cell
For example, to refer to cells A1:A10 in Sheet2, you type Sheet2!A1:A10.
After this you will write formulas ıf you add new excel only you can add formula SheetXX!A1:A10.
Related
I have sheet named origin that displays set of data Col A:B via ImportRange
I have a sheet named destination
What I wanted to do:
When ImportData changes (a new item is added in the origin sheet) I wanted to copy that
item and paste it in the destination sheet.
What I dont want to happen:
Is copy data that are already existing in the destination sheet.
When ImportData Origin is sorted, the display in the origin sheet is
also changed. In this case I should still be able to copy data that
are not existing in the destination sheet even if both sheets are no
longer sorted the same.
Any idea on how I can achieve this?
Thank you so much
Explanation:
I would advice you to use a formula in the destination sheet, something like:
UNIQUE(IMPORTRANGE("url", "origin!A1:B"))
so you can have the unique items of the origin sheet in the destination sheet.
The reason that I am suggesting that is because you are looking for a trigger behaviour. Namely, when a new value is added in a cell, grab this value and send it to another spreadsheet. The problem with this approach is that Google-Apps-Script triggers are not triggered by scripts nor formulas, but only by user edits. In other words, if a cell is modified by your import range formula, there is not a direct GAS solution which can figure that out. Only workarounds exist which might have limitations and they are very specific to your exact use case.
Workarounds
See this thread for some info and references.
You can use the Properties Service which you can store some sort of data that is bound the script. In this way, you can create a Time-driven trigger which will run every 1 minute or so and check if there are changes to the original data. If a new value is added, update the property and send the data to the destination sheet. If no new data is added, do nothing.
I want to create a sheet by SpreadsheetApp.create(); and to fill a QUERY in this new generated sheet via cell.setFormula and IMPORTRANGE to get data of another Sheet.
It doesn't work because the sheets are not connected. If I do so manually the QUERY works.
Is there a way to connect two sheets via script?
You could create a variable with the locations of the sheets by the ID's. Then, access the sheet remotely via the script. Save the cell variable and paste this over into the first sheet.
Psuedo-Code Example
Sheet1 = SpreadsheetApp.getSheetByID('IDofSheetOne');
SpreadsheetApp.create();
Sheet2 = SpreadsheetApp.getSheetByID('IDofSheetTwo'); // the one just created, you'd probably have to use some kind of get to get this ID.
Now from here, you can just say, Sheet1.doWhatever() and Sheet2.doWhatever().
Thats how you can access more than one sheet at a time.
I am trying to modify the following script, which saves a selected range to a new CSV file on Google drive.
https://developers.google.com/apps-script/articles/docslist_tutorial?hl=en
Please see: Section 3: Saving a selected Range to a CSV file
I would like to however append an existing CSV file with defined (named) range that I already created on Google Drive - I don't want to be prompted for its name. If and only if the CSV file not exist, then I want to create the new file.
This script should run via time-drive trigger (so that it runs automatically every minute and saves required range into csv file)
I would greatly appreciate your help how to modify this code.
I have copied multiple sheets from one spreadsheet to another using the copyTo(spreadsheet) method. As the documentation suggests,
The copied sheet will be named "Copy of [original name]".
How can I rename that sheet, which is now effectively located in a different spreadsheet than the one hosting my script?
I know this can be done with a Spreadsheet when making the copy but I don't believe this is possible with just a copy of a sheet (with a single call).
I think you'll need to get it by the 'Copy of' name and use setName.
I am trying to create a script which performs the following:
I have a Google Sheet which contains a variable number of file names (could be 10, could be 1,000). I need to read this sheet and for each entry, search My Drive (and shared with me) and add the item to another folder on My Drive (same function as pressing Shift+Z).
I currently have a script which searches Drive and provides the url, but this takes user input, takes one expression at a time and does not "add to" another folder.
Use the makeCopy() method:
makeCopy(name, destination)
destination is the directory to copy the file into. The destination parameter is not a string. It's a folder type.