如何检查单元格是否为空,如果是则跳过它

How to check if the cell is empty, if so skip it

我想再添加 1 行来检查特定行是否为空。如果为空,我希望它为 return.

    if (index === 0) return; // this to check header
    if (row[52]) return; // this to check if the row have data. if have it returns.

这部分的完整代码如下。

function createNewGoogleDocs() {
  //This value should be the id of your document template that we created in the last step
  const googleDocTemplate = DriveApp.getFileById('Google Doc');
  
  //This value should be the id of the folder where you want your completed documents stored
  const destinationFolder = DriveApp.getFolderById('Folder');
  //Here we store the sheet as a variable
  const sheet = SpreadsheetApp
    .getActiveSpreadsheet()
    .getSheetByName('List');
  
  //Now we get all of the values as a 2D array
  const rows = sheet.getDataRange().getValues();
  
  //Start processing each spreadsheet row
  rows.forEach(function(row, index){
    //Here we check if this row is the headers, if so we skip it
    if (index === 0) return;
    //Here we check if a document has already been generated by looking at 'Document Link', if so we skip it
    if (row[52]) return;
    //Using the row data in a template literal, we make a copy of our template document in our destinationFolder
    const copy = googleDocTemplate.makeCopy(`${row[4]} List` , destinationFolder)
    //Once we have the copy, we then open it using the DocumentApp
    const doc = DocumentApp.openById(copy.getId())
    //All of the content lives in the body, so we get that for editing
    const body = doc.getBody();

SpreadsheetApp.Range.getValues() returns 空白单元格中的空字符串,考虑到这一点,使用以下表达式:

row[52] === ''

相关