After loading the local CSV file into the spreadsheet, I would like to put in a blank code.
I've created a button on the spreadsheet from which I call function.I'd like to do everything in one click, but I've called csv.gs and ok.gs twice, so I'll do it in one click if possible.
Server-side code
csv.gs
function showDialog(){
vars = SpreadsheetApp.getActiveSpreadsheet();
console.log(ss.getName());
// Replace the sheet name.
varsh=ss.getSheetByName("makelist simple";
// Clear all sheets
sh.clear();
}
varhtml=HtmlService.createHtmlOutputFromFile('dialog');
SpreadsheetApp.getUi().showModalDialog(html, "CSV Upload";
function uploadCsv(form){
var blob=form.myFile;
varcsvText=blob.getDataAsString('shift-jis');
values = Utilities.parseCsv(csvText);
SpreadsheetApp.getActiveSheet().getRange(1,1, values.length, values[0].length).setValues(values);
}
dialog.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
<input name="myFile" type="file">
<button onclick="uploadCsv(this.parentNode);">upload</button>
</form>
<script>
function uploadCsv(form){
Google.script.run.withSuccessHandler(function(){
google.script.host.close();
}).uploadCsv(form);
}
</script>
</body>
</html>
ok.gs
functionInsertRowBefore(){
vars = SpreadsheetApp.getActiveSpreadsheet();
varsh=ss.getSheetByName("makelist simple";
// insert ten new lines after the tenth line of the sheet
sh.insertRowsBefore (68,10);
}
I thought if I called InsertRowBefore to add a line to the trigger, it would take just one click, but I couldn't call from here.
Error Description:
Cannot invoke SpreadsheetApp.getUi() from this context
at [unknown function] (csv:15)
If you have any knowledge that there is such a way, please take good care of me.
google-apps-script
instead of calling InsertRowBefore function
The following code was added to the end of the showDialog function.
// Add one line to line 9
var spreadsheet=SpreadsheetApp.getActive();
spreadsheet.getActiveSheet().insertRowsAfter(spreadsheet.getRange("A10").getRow(), 1);
© 2024 OneMinuteCode. All rights reserved.