插入 IF 条件

Inserting an IF condition

我有以下脚本,它从源 sheet 将行导入活动 sheet。导入一行后,该行标记为“IMPORTED”,拥有源 sheet。我需要一个 IF 条件,这样如果一行被标记为“IMPORTED”,该行将不会复制到活动 Sheet。 该脚本在没有 IF 条件的情况下工作完美,但在 IF 条件下脚本无法 运行.

  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Import Dockets')
    .addItem('Import Dockets','deliveries')
    .addToUi();
}
function deliveries(){
  // Gets the active sheet.
  var sheet = SpreadsheetApp.getActiveSheet();
  
  // Gets a different spreadsheet from Drive using
  // the spreadsheet's ID. 
  var bookSS = SpreadsheetApp.openById(
    "SHEETID" 
  );

  // Gets the sheet, data range, and values of the
  // spreadsheet stored in bookSS.
  var bookSheet = bookSS.getSheetByName("DOCKETS");
  var lr = bookSheet.getLastRow();
  var bookRange = bookSheet.getRange(1,1,lr,58);
  var bookListValues = bookRange.getValues();

  // Add those values to the active sheet in the current
  // spreadsheet. This overwrites any values already there.
  var lr = bookSheet.getLastRow();
  
  bookListValues.forEach((r, i) => {
  var impor = r[56];  
  if (impor != 'IMPORTED'){
  sheet.getRange(1, 1, bookRange.getHeight(), bookRange.getWidth()) 
    .setValues(bookListValues)

  var lr = bookSheet.getLastRow();
  bookSheet.getRange(2,57,lr,1).setValue("IMPORTED");
  
  // Rename the destination sheet and resize the data
  // columns for easier reading.
  sheet.setName("DOCKETS");
  sheet.autoResizeColumns(1, 25);

  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('DOCKETS'); // adjust this to the name of your sheet
  const values = sh.getRange('F2:F'+sh.getLastRow()).getValues().flat().map(v=>[v.slice(0,v.indexOf(','))]);
  
  sh.getRange(2,9,values.length,1).setValues(values); // paste them in column B
   
}

非常感谢任何帮助。谢谢

这样试试

function deliveries() {
  const ash = SpreadsheetApp.getActiveSheet();
  const dss = SpreadsheetApp.openById("SHEETID");
  const dsh = dss.getSheetByName("DOCKETS");
  const brg = dsh.getRange(1, 1, dsh.getLastRow(), 58);
  const bvs = brg.getValues();
  let arr = [];
  bvs.forEach((r, i) => {
    if (r[56] != 'IMPORTED') {
      arr.push(r);
    }
  })
  if(arr) {
    ash.setName("DOCKETS")
    ash.getRange(2,1,a.length,a[0].length).setValues(a);
  }
}