带有onEdit Trigger的脚本在浏览器上有效,而在移动设备上无效

时间:2019-11-21 17:18:08

标签: google-apps-script google-sheets spreadsheet

我有一个代码,可以从类似表单的工作表中获取数据,并将其放在表等其他工作表上。

它与onEdit(e)触发器一起运行,该触发器仅应在编辑特定单元格时触发,在我的浏览器上运行良好,但在iPad上,代码不起作用。

这是我的代码

function onEdit(e) {
  var sheet =  SpreadsheetApp.getActive().getSheetByName("Apontamento");

  var row = e.range.getRow();
  var col = e.range.getColumn();

  if(col == 8 && row ==5){
  SpreadsheetApp.getActive().getActiveSheet().getRange("H5").setValue(false);
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('1:1').activate();
  spreadsheet.getActiveSheet().insertRowsAfter(spreadsheet.getActiveRange().getLastRow(), 1);
  spreadsheet.getActiveRange().offset(spreadsheet.getActiveRange().getNumRows(), 0, 1, spreadsheet.getActiveRange().getNumColumns()).activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Apontamento'), true);
  spreadsheet.getRange('G3').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('A2').activate();
  spreadsheet.getRange('Apontamento!G3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Apontamento'), true);
  spreadsheet.getRange('G5').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('B2').activate();
  spreadsheet.getRange('Apontamento!G5').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Apontamento'), true);
  spreadsheet.getRange('G7').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('C2').activate();
  spreadsheet.getRange('Apontamento!G7').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.getRange('D2').activate();
  spreadsheet.getCurrentCell().setFormula('=C2-B2');
  spreadsheet.getRange('E2').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Apontamento'), true);
  spreadsheet.getRange('F2').activate();
  spreadsheet.getCurrentCell().setFormula('=procv(E2;\'CÓDIGO DE ATIVIDADES\'!C:E;3;0)');
  spreadsheet.getRange('G9').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('Apontamento!G9').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Apontamento'), true);
  spreadsheet.getRange('D5').activate();
  spreadsheet.getRange('D7:F7').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES'), true);
  spreadsheet.getRange('B:B').activate();
  spreadsheet.getActiveRangeList().setNumberFormat('HH:mm:ss');
  spreadsheet.getRange('C:C').activate();
  spreadsheet.getActiveRangeList().setNumberFormat('HH:mm:ss');
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('APONTAMENTO'), true);
  spreadsheet.getRangeList(['D7', 'F7', 'D9:F9']).activate()
  .clear({contentsOnly: true, skipFilteredRows: false});
  }

the "form-like" sheet

选中“ SALVAR”下面的复选框后,脚本将运行。

我如何使其在iPad和其他移动设备上运行?

编辑:

大家好,

我已经更改了代码,以摆脱“活动部分”,但仍然无法正常工作,请您能帮我吗?

function onEdit(e) {
  var sheet =  SpreadsheetApp.getActive().getSheetByName("Apontamento");

  var row = e.range.getRow();
  var col = e.range.getColumn();

  if(col == 8 && row ==5){
  SpreadsheetApp.getActive().getSheetByName('APONTAMENTO').getRange("H5").setValue(false);
  var spreadsheet = SpreadsheetApp.getActive();
  var SH = spreadsheet.getSheetByName('APONTAMENTO DE ATIVIDADES');
  var SH2 = spreadsheet.getSheetByName('APONTAMENTO');
  SH.insertRowsAfter(1,1);
  SH.getRange('A2').setValue(SH2.getRange('G3').getValue());
  SH.getRange('B2').setValue(SH2.getRange('G5').getValue());  
  SH.getRange('C2').setValue(SH2.getRange('G7').getValue());    
  SH.getRange('D2').setFormula('=C2-B2');
  SH.getRange('E2').setValue(SH2.getRange('G9').getValue()); 
  SH.getRange('F2').setFormula('=vlookup(E2;\'CÓDIGO DE ATIVIDADES\'!C:E;3;0)');
  SH2.getRange('D3').setValue('');
  SH2.getRange('D5').clear();
  SH2.getRange('D7').clear();
  SH2.getRange('F5').clear();
  SH2.getRange('F7').clear();
  SH2.getRange('D9').setValue('');
  }

0 个答案:

没有答案