Google sheets Google Sheets宏不粘贴公式

Google sheets Google Sheets宏不粘贴公式,google-sheets,google-sheets-formula,Google Sheets,Google Sheets Formula,请帮助使用Google sheets宏。尝试简单的东西作为开始。宏需要清除B2单元格并粘贴公式(importhtml),如下所示。然后,它必须对单元格B43执行相同的操作(如果可行的话,可能会在该表的多个单元格中执行此操作) 谷歌网页链接: 奇怪的是,它在B43中工作,但B2为空 function Untitledmacro() { // Clear B2 and then paste formula var spreadsheet = SpreadsheetApp.getActiv

请帮助使用Google sheets宏。尝试简单的东西作为开始。宏需要清除B2单元格并粘贴公式(importhtml),如下所示。然后,它必须对单元格B43执行相同的操作(如果可行的话,可能会在该表的多个单元格中执行此操作)

谷歌网页链接:

奇怪的是,它在B43中工作,但B2为空

 function Untitledmacro() {

// Clear B2 and then paste formula

  var spreadsheet = SpreadsheetApp.getActive();

  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DATA'), true);
  spreadsheet.getRange('B2').activate();

  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
};

  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DATA'), true);
  spreadsheet.getRange('B2').activate();

  spreadsheet.getCurrentCell().setFormula('=IMPORTHTML("https://www.investing.com/commodities/real-time-futures","table",1)');

// Clear B43 and then paste formula


  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DATA'), true);
  spreadsheet.getRange('B43').activate();

  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});

  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DATA'), true);
  spreadsheet.getRange('B43').activate();

  spreadsheet.getCurrentCell().setFormula('=IMPORTHTML("https://www.investing.com/indices/indices-futures","table",1)');



  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DATA'), true);
看看这是否有帮助

函数clearAndSetformula(){
const sheet=SpreadsheetApp.getActive().getSheetByName('DATA');
常量单元格=[“B2”,“B43”];
常数公式=[
'=IMPORTHTML(“https://www.investing.com/commodities/real-time-futures“,“表”,1)”,
'=IMPORTHTML(“https://www.investing.com/indices/indices-futures“,“表”,1)”
];
cells.forEach((cell,i)=>sheet.getRange(cell).clear({contentsOnly:true,skipFilteredRows:true}).setFormula(公式[i]);

};你好,David,我们无法访问您共享的电子表格。请修复权限。