I have a dialog, on which there are some textarea and an Insert button to import data from the textarea into Google spreadsheet. Here is the code:
<td><button style="width:40%" onclick="insert();google.script.run.onEdit();">Insert</button></td>
Here is the html code
function insert() {
var title = document.getElementById('Qnumber').value;
var content1 = document.getElementById('content').value;
var content = replaceContent(content1);
var formula1 = document.getElementById('formula').value;
var formula = replaceFormula(content1,formula1)
var unit = document.getElementById('unit').value;
var option1 = document.getElementById('A').value;
var option2 = document.getElementById('B').value;
var option3 = document.getElementById('C').value;
var option4 = document.getElementById('D').value;
if (document.getElementById('formula').value !=="") {
google.script.run.enterName1(title,content,formula,unit);
}
else {
google.script.run.enterName2(title,content,option1,option2,option3,option4);
}
}
Here is the gs code
function enterName1(title,content,formula,unit) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('tests');
var title = sh.getRange(Number(title)+1,1,1,3).setFormulas([[title, '="'+content+'"', '=round('+formula+';3)'+'&" '+unit+'."']]);
}
function enterName2(title,content,option1,option2,option3,option4){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('tests');
var title = sh.getRange(Number(title)+1,1,1,3).setFormulas([[title, '="'+content+'"', '=if(column()=3;"'+option1+'";if(column()=4;"'+option2+'";if(column()=5;"'+option3+'";if(column()=6;"'+option4+'"))))']]);
}
When I run the program, the "enterName1" function works and the "enterName2" function does not. Can anyone help me to fix it, thanks.