如何从google工作表中的onEdit事件启动侧边栏

时间:2018-01-26 17:09:41

标签: google-apps-script

要从google工作表中的onEdit事件开始一个侧边栏,这是我的代码,我可能是错的

function onEdit(e){
  var data=[];
  var sourceS = "Livio - Tarde - Revisar",
      targetS = "Reportes - Asignación",
      sourceR = {
        column: 4,
        row: 4,
        endRow: 76,
        endColumn: 26
      }
  if (e.source.getActiveSheet().getName() === sourceS || e.range.rowStart < sourceR.row || e.range.columnStart < sourceR.column || e.range.rowStart > sourceR.endRow || e.range.columnStart > sourceR.endColumn){
    var row = e.range.getRow();
    Logger.log(e.range.getA1Notation())
    var mergedRanges = e.source.getActiveSheet().getRange(row, 1).getMergedRanges();
    for (var i = 0; i < mergedRanges.length; i++) {
      Logger.log(mergedRanges[i].getA1Notation()+" Docente: "+mergedRanges[i].getDisplayValue());
      data['docente'] = mergedRanges[i].getDisplayValue();
    }
    Logger.log( e.source.getActiveSheet().getRange(row, 2).getValue())
    var mergedRanges2 = e.source.getActiveSheet().getRange(row, 28).getMergedRanges();
    for (var i = 0; i < mergedRanges2.length; i++) {
      Logger.log(mergedRanges2[i].getA1Notation()+" Horas Totales: "+mergedRanges2[i].getDisplayValue());
      data['ht'] = mergedRanges[i].getDisplayValue();
    }
    var mergedRanges3 = e.source.getActiveSheet().getRange(row, 29).getMergedRanges();
    for (var i = 0; i < mergedRanges3.length; i++) {
      Logger.log(mergedRanges3[i].getA1Notation()+" Horas Extras: "+mergedRanges3[i].getDisplayValue());
      data['hex'] = mergedRanges[i].getDisplayValue();
    }

    var html = HtmlService.createHtmlOutput('<div style="padding: 5px;">'+
                                            '<div>Docente: <p id="docente"></p></div>'+
                                            '<div>Horas Totales: <p id="ht"></p></div>'+
                                            '<div>Horas Extras: <p id="hex"></p></div></div>')
    .setTitle('Tracking sidebar')
    .setWidth(300);

    var ui = SpreadsheetApp.getUi();
    ui.showSidebar(html);

    Logger.log("docente: "+data['docente'])
    return data
  }
}

侧边栏仅从菜单开始或从编辑器运行功能

0 个答案:

没有答案