Changing cells of a google sheet file through another sheet - google-apps-script

I have a big google sheet file with more thousand rows.
My goal is to create another smaller spreadsheet which imports a given line from the big database (just for show, I don't want to edit it oruse it) and after that I'd like to add some data to that given line.
I was able to do it with IMPORTRANGE function, but after I change to another row, the other rows I edited before don't keep the information I entered.
Also, I can't use my sheet to select a row in the big database and add a permanent data to it.
Do you have any idea how could I solve this problem? (Google script would be fine too, I really have no idea how to do this).
Thanks

Copy Selected Row
From one spreadsheet to another.
function copySelectedRow(){
var ss1=SpreadsheetApp.getActive();
var sh1=ss1.getSheetByName('Data');//Change data to the name of the sheet that you wish to copy from in ss1
var rg1=sh1.getRange(sh1.getActiveCell().getRow(),1,1,sh1.getLastColumn());//Select a cell in the row that you wish to copy and then run this function.
var vA1=rg1.getValues();
var ss2=SpreadsheetApp.openById('ID of Spreadsheet Copying To');
var sh2=ss2.getSheetByName('Data');//Change data to the name of the sheet that you wish to copy to in ss2
sh2.appendRow(vA1[0]);
}

Related

How to copy the whole sheet and paste results in a specific sheet

I am trying to copy the whole contents from one sheet (source) to another specific sheet (destination), in the same spreadsheet (Google Sheets)
How can I achieve that?
I tried SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet(), but this creates a new sheet every time I trigger the script
I get that you already have a trigger set up and you want to make it copy all the contents of one sheet into another. Well, in that case you only need to use Range.copyTo() as #Tanaike suggested. Take this as one of the possible solutions:
function so64978677() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
sourceSheet.getDataRange().copyTo(targetSheet.getRange(1, 1));
}
Please, don't hesitate to ask me any additional questions.

Google Sheets: how to copy formula down on rows added through Google Form responses

I am working with Google Form results data that is being dropped into a Google Sheet tab and I added a column to calculate the percentage of the quiz scores that are then being pulled onto a tracking tab in the same sheet that calculates their percentage completed. Right now the Percent Column is appearing as a blank field no matter which formula I've tried. I am wondering if there is a different formula would work that would automatically apply to the column when new responses are added? Or would a Google Script be a better option?
I am wanting to keep the raw result data on the same sheet since it is compiling all of the quizzes into one Google Sheet with one tab pulling the Percentages to show completion rate.
I have tried ARRAYFORMULA and the formula that works if you copy it manually to each entry is "=left(C2,find("/",C2)-1)/(right(C2,len(C2)-find("/",C2)))"
Try
=Arrayformula(if(len(C2:C), left(C2:C,find("/",C2:C)-1)/(right(C2:C,len(C2:C)-find("/",C2:C))),))
and see if that works?
This function will add a formula in the last column when a new formresponse will be added to the sheet:
function setFormula() {
var ss=SpreadsheetApp.openById('SHEET_ID');
var sheet=ss.getSheetByName('SHEET_NAME');
var lastRow = sheet.getLastRow();
var formulaRange1 = sheet.getRange(lastRow, sheet.getLastColumn());
formulaRange1.setValue('=IF($A'+lastRow+'="";"";TODAY()-$Q'+lastRow+')');
}
Your formula must be adjusted accordingly. Just make sure that lastRow is inside the string instead of the line number and add a onFormResponse Trigger. I've added this script to the form, not to the spreadsheet.

Google Apps Script- Copy & paste data from column one row at a time

(Please note: JavaScript, Stack Overflow posting, & Google Script novice)
THE BACKGROUND: I'm attempting to use a Google Sheet Email Notification Add On to trigger notifications when a specific value is seen in a Google Sheet. The config requirements of the add on look for a TextValue, however it has trouble finding the value in a pivot table (where my data is sorted). I've tried moving the data to another sheet with a QUERY formula, however the resultant value is not seen by the add on as a TextValue but rather a cell formula.
My workaround to this is to use a script to copy & paste the data from my pivot to a separate sheet. I used this post as my guide to create my script. It works, however because it pastes all column values at once, the add on is having trouble identifying the trigger TextValue.
THE QUESTION: instead of having the entire column copied and pasted at once, how can I tweak this script to copy and paste a row at a time with a slight delay (1-2 seconds)? This delay will allow the add on to see the the target TextValue and execute the notification (I've tested this manually and it works as expected). Any help in modifying this script (or completely changing the logic if necessary) would be greatly appreciated!!
//Copy contents of inventory column daily to run notification add on
function readInventoryNum() {
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Inventory Totals");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Testing123");
// Copy from 2nd row, 7th column, all rows for one column
var valuesToCopy = sheetFrom.getRange(2, 7, sheetFrom.getLastRow(), 1).getValues();
//Paste to another sheet from first cell onwards
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}

copyTo range does not copy drawings?

When I use copyTo to copy an entire sheet, drawings get copied but I don't want to copy the entire sheet so I tried to use copyTo on a range but drawings do not get copied. Anyone know if this is expected behavior or a bug? For example if a drawing is in A4 ...
function test() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var test1 = ss.getSheetByName("test1");
var test2 = ss.getSheetByName("test2");
// this does not copy drawing to sheet test2
var rangeToCopy = test1.getRange(1,1,5,1);
rangeToCopy.copyTo(test2.getRange(1,1));
// this copies drawing to new sheet Copy of test1
test1.copyTo(ss);
}
I realize there are two copyTo's, one for sheets and one for ranges, just would have expected they both should copy drawings.
no, it doesnt copy drawings. a big part of it is that drawings do not sit on a given cell or range.
you can confirm this by inserting rows above the drawing. sometimes google shifts the drawing down and sometimes doesnt, so it's not tied to specific rows, at least not strictly.
you can also confirm that copying ranges manually with the web interface also doesnt copy the drawings.
one solution is to convert the drawing to an image and host it somewhere (like a google sites cabinet with public access) and use cell formula `=IMAGE("http://path.to.image.png")' which will get copied.
another way if you must use drawings, is to copy the entire sheet into a new sheet, then manually copy the ranges that you didnt want to overwrite from your destination sheet, then delete the original destination sheet and rename the new sheet with the destination name.

Google Spreadsheets with Form Vinculated copy

I'm trying to copy a spreadsheet with the responses of a form thought drive API.
https://developers.google.com/drive/v2/reference/files/copy
All files from my drive are working fine but only this spreadsheet that persist my form answers that create a duplicate form instead of only copying the spreadsheet itself.
You can try to reproduce the problem using the given Id. After copying you will notice that both spread sheet and form will be copied. This should not be a problem if I could erase the form but in the response of the copy procedure I don't get any advice about the form that is being copied together.
File id: 0Aqq-9JjR-lUydHRKVEJ2SThGMjJlVjVqczkyWlVCWUE
Please, help me. I'm desperate.
If you are only trying to copy the spreadsheet of the form, try this:
var fromSheet = ***whatever***;//this is the sheet attached to your form
var toSheet = ***whatever***;//this will be the sheet that you are copying to
var range = **whatever***;//this is the range you are copying over. If you are using dynamic ranges (ie varying number of rows), you may want to **getDataRange()** and **getLastRow** to build a more flexible range
function myCopyCat(){
myValues = fromSheet.getRange(range).getValues();//'copies' all of your data within range from fromSheet to an array
toSheet.getRange(range).setValues(myValues);//'pastes' all of your data into cells on toSheet
}