Reputation: 21823
I have a Google Spreadsheet with a sheet called Wrapped Sheet
for the responses collected from a Google Form. On every new added response (thus the onEdit function), I want to call the Wrap Text
option on all cells. I opened the script editor and created onEdit.gs
with the following code:
function onEdit(){
var activeSheet = SpreadsheetApp.getActiveSpreadsheet();
if(activeSheet.getName() == "Wrapped Sheet") {
var dataRange = activeSheet.getRange(1,1,data.length,headers.length);
dataRange.setWrap(true);
}
}
However, the function is not triggered on a new response. Additionally, calling it manually from within the script editor does not report any error.
Upvotes: 3
Views: 9337
Reputation: 131
If every S.O. answer was a link to read docs, S.O. would be kinda pointless.
So, as orschiro mentioned... And as mentioned in this S.O. answer... https://webapps.stackexchange.com/questions/88543/how-to-automatically-wrap-text-to-new-responses-from-a-form-in-a-google-spreadsh
The actual answer is:
function wrap(e) {
e.range.setWrap(true);
}
Upvotes: 4
Reputation: 3590
You should go and give the google script event docs a full read.
You'll find out that there is a specific event for your use case: on form submit. Instead of executing your code when the sheet is modified (function onEdit(e)) you should execute the code when the form is submitted.
In the same docs you can find an exemple of how to use this trigger.
NOTE: Be aware that there are 2 types of events triggers: simple ones and installed ones. The onFormSubit event responds to a installed trigger (again you'll find everything in the docs).
Upvotes: 2