úterý 24. března 2015

Write value in cell / cells

How to write value in cells with Google Apps script


write to cells of the active workbook

function TextToCell1() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange(1,3);
  var data = range.setValue('css004');
}



write a new line in the active workbook

function TextToCell1() {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow(['Hello world', 'Agent 007', 'Today']);
}



write to a defined workbook to the defined Sheet

function WriteToSpreadsheet() {
   //ID Spreadsheet in Google 
   var ss = SpreadsheetApp.openById("1Y_hnVcR5FoP-_6VDsCv-aOqSAQ");
   var name = ss.getName();

   var sheet = ss.getSheetByName('Sheet1');
   var range = sheet.getRange(5,5);
   range.setValue('agent 007');
}




write cycle for 1-4

function WriteInFor() {

   var ss = SpreadsheetApp.openById("1Y_hnVcR5FoP-_6qSAQYw5tR40yb-VeRirCs");
   var name = ss.getName();  

   var sheet = ss.getSheetByName('Sheet1');
 
   for (var i = 1; i < 5; i++) {
      var range = sheet.getRange(8,i);
       range.setValue(i);
  }
}



write cycle for 1-4 including conditions

function WriteForAndIf() {
   var ss = SpreadsheetApp.openById("1Y_hnVcR5FoP-_6VDsCv-aOqSAQYw5tR40yb-VeRirCs");
   var name = ss.getName();  

   var sheet = ss.getSheetByName('Sheet1'); 
 
    for (var i = 1; i < 5; i++) {
        var range = sheet.getRange(8,i);
         range.setValue(i);
        if (i == 3) range.setValue("None");
   }
}

Žádné komentáře:

Okomentovat