清除单元格时出现错误-简单脚本

时间:2019-06-14 21:02:38

标签: google-apps-script google-sheets

我有一个非常简单的脚本,应该清除工作表中的单元格。我删除了所有脚本,但仅一行尝试缩小范围,但仍然出现错误。很抱歉,发生服务器错误。请稍等,然后重试。

function clearRange() {
  var sheet = SpreadsheetApp.getActive().getSheetByName('QUOTE SHEET');
  sheet.getRange('A30').clearContent();
}

我过去曾在另一张纸上进行此工作。我在这里想念东西吗?

这是另一张纸上的作品

function Clear() {

  //////////////          Clear Discovery Sheet             ///////////////

  var discoverySheet = SpreadsheetApp.getActive().getSheetByName('Discovery Sheet');
  discoverySheet.getRange('A7').clearContent();
  discoverySheet.getRange('E7').clearContent();
  discoverySheet.getRange('A15').clearContent();
  discoverySheet.getRange('E15').clearContent();
  discoverySheet.getRange('A23').clearContent();
  discoverySheet.getRange('E23').clearContent();
  discoverySheet.getRange('A31').clearContent();
  discoverySheet.getRange('E31').clearContent();
  discoverySheet.getRange('B2').clearContent();
  discoverySheet.getRange('B4').clearContent();
  discoverySheet.getRange('F4').clearContent();

  var name = SpreadsheetApp.getActive().getSheetByName('Discovery Sheet');
  var email = Session.getActiveUser().getEmail();
  Logger.log(email);
  name.getRange('a38').setValue(email);

  //////////////          Clear Quote Sheet             ///////////////

  var quoteSheet = SpreadsheetApp.getActive().getSheetByName('QUOTE SHEET');
  quoteSheet.getRange('A17').clearContent();
  quoteSheet.getRange('A18').clearContent();
  quoteSheet.getRange('B17').clearContent();
  quoteSheet.getRange('B18').clearContent();
  quoteSheet.getRange("E26:E35").clearContent();
  quoteSheet.getRange("F26:F35").clearContent();
  quoteSheet.getRange('F22').clearContent();
  quoteSheet.getRange('F23').clearContent();




  //////////////          device payment             ///////////////

  var quoteSheet = SpreadsheetApp.getActive().getSheetByName('QUOTE SHEET');
  quoteSheet.getRange("E26:E34").setValue('$0.00');  
  quoteSheet.getRange("F26:F34").setValue('$0.00'); 
  quoteSheet.getRange("C26:C34").setValue('$0.00');  
  quoteSheet.getRange("A26:A35").setValue('Select Phone Model ');  
  quoteSheet.getRange("A17").setValue('None'); 
  quoteSheet.getRange("A18").setValue('None'); 
  quoteSheet.getRange("e17").setValue('0%'); 
  quoteSheet.getRange("b17").setValue('0'); 
  quoteSheet.getRange("b18").setValue('0'); 
  quoteSheet.getRange("a21").setValue('Select Plan'); 
  quoteSheet.getRange("F17").setValue("0.00");  
  quoteSheet.getRange("b22").setValue('0%');

    var cell = quoteSheet.getRange("D26");
  cell.setFormula('=if(B26="N.A",0,if(B26="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A26)),B26/6,B26/24)))');
    var cell = quoteSheet.getRange("D27");
  cell.setFormula('=if(B27="N.A",0,if(B27="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A27)),B26/6,B27/24)))');
    var cell = quoteSheet.getRange("D28");
  cell.setFormula('=if(B28="N.A",0,if(B28="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A28)),B28/6,B28/24)))');
    var cell = quoteSheet.getRange("D29");
  cell.setFormula('=if(B29="N.A",0,if(B29="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A29)),B29/6,B29/24)))');
    var cell = quoteSheet.getRange("D30");
    cell.setFormula('=if(B30="N.A",0,if(B30="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A30)),B30/6,B30/24)))');
    var cell = quoteSheet.getRange("D31");
  cell.setFormula('=if(B31="N.A",0,if(B31="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A31)),B31/6,B31/24)))');
    var cell = quoteSheet.getRange("D32");
  cell.setFormula('=if(B32="N.A",0,if(B32="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A32)),B32/6,B32/24)))');
    var cell = quoteSheet.getRange("D33");
  cell.setFormula('=if(B33="N.A",0,if(B33="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A33)),B33/6,B33/24)))');
    var cell = quoteSheet.getRange("D34");
  cell.setFormula('=if(B34="N.A",0,if(B34="CPE/No DPP",0,if(ISNUMBER(SEARCH("watch",A34)),B34/6,B34/24)))');
    var cell = quoteSheet.getRange("B21")
  cell.setFormula('=IFERROR(VLOOKUP(A21,PLANS!A4:B1000,2,false),0)');



  //////////////          Totals             ///////////////

    var cell = quoteSheet.getRange("G26");
  cell.setFormula('=SUM(D26,E26,F26,C26)')
    var cell = quoteSheet.getRange("G27");
  cell.setFormula('=SUM(D27,E27,F27,C27)')
    var cell = quoteSheet.getRange("G28");
  cell.setFormula('=SUM(D28,E28,F28,C28)')
    var cell = quoteSheet.getRange("G29");
  cell.setFormula('=SUM(D29,E29,F29,C29)')
    var cell = quoteSheet.getRange("G30");
  cell.setFormula('=SUM(D30,E30,F30,C30)')
    var cell = quoteSheet.getRange("G31");
  cell.setFormula('=SUM(D31,E31,F31,C31)')
    var cell = quoteSheet.getRange("G32");
  cell.setFormula('=SUM(D32,E32,F32,C32)')
    var cell = quoteSheet.getRange("G33");
  cell.setFormula('=SUM(D33,E33,F33,C33)')
    var cell = quoteSheet.getRange("G34");
  cell.setFormula('=SUM(D34,E34,F34,C34)')



  //////////////          RETAIL PRICE             ///////////////

    var cell = quoteSheet.getRange("B26");
  cell.setFormula("=IFERROR(VLOOKUP(A26,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B27");
  cell.setFormula("=IFERROR(VLOOKUP(A27,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B28");
  cell.setFormula("=IFERROR(VLOOKUP(A28,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B29");
  cell.setFormula("=IFERROR(VLOOKUP(A29,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B30");
  cell.setFormula("=IFERROR(VLOOKUP(A30,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B31");
  cell.setFormula("=IFERROR(VLOOKUP(A31,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B32");
  cell.setFormula("=IFERROR(VLOOKUP(A32,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B33");
  cell.setFormula("=IFERROR(VLOOKUP(A33,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")
    var cell = quoteSheet.getRange("B34");
  cell.setFormula("=IFERROR(VLOOKUP(A34,'PHONES 2 (Do Not Edit)'!A:C,2,false),0)")

  //////////////          BUNDLE PACKAGES             ///////////////
    var cell = quoteSheet.getRange("E18");
  cell.setFormula("=D18-E19")
    var cell = quoteSheet.getRange("D18");
  cell.setFormula('=if(A17="Diamond Package",B17*200,if(A17="Platinum Package",B17*150,0))+if(A18="Diamond Package",B18*200,if(A18="Platinum Package",B18*150,0))')


  //////////////          Name Section             ///////////////

      var cell = quoteSheet.getRange("f4");
  cell.setFormula("='Discovery Sheet'!B2")
      var cell = quoteSheet.getRange("f5");
  cell.setFormula("='Discovery Sheet'!B4")


}

更新脚本:

function test(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('QUOTE SHEET');

var cell = sheet.getRange("A30:A38");
var cellBC = sheet.getRange("B30:V38");
  var cellEG = sheet.getRange("E30:G38");
      var cellB17_18 = sheet.getRange("B17:B18");
          var cellc17_19 = sheet.getRange("B19:B20"); 
              var celld17_20 = sheet.getRange("B21:B22");
                  var celle17_21 = sheet.getRange("B23:B24");

cell.setValue("Select Phone Model ");
cellBC.setValue("");
  cellEG.setValue("");
      cellB17_18.setValue("");
          cellc17_19.setValue("");
              celld17_20.setValue("");
                  celle17_21.setValue("");


}

1 个答案:

答案 0 :(得分:0)

这里的问题是由于某种原因,我的工作簿“损坏”了,我制作了一个副本并使用了确切的脚本,并且对我有用。这一定与Google的事情有关。因此,如果其他任何人遇到这种情况,请先尝试。