简体   繁体   English

带有空白行的自动填充数据 - Google 表格/Google Apps 脚本

[英]AutoFill Data with Blank Rows - Google Sheets / Google Apps Script

I have the below spreadsheet that I would like to AutoFill the persons name.我有下面的电子表格,我想自动填充人名。 the issue is that there are blank rows between the names.问题是名称之间有空白行。 Each name is in line with a sku2 and needs to be inline with all locations.每个名称都与一个 sku2 一致,并且需要与所有位置内联。 there can be up to 10 blank rows (due to how many locations).最多可以有 10 个空白行(取决于位置的数量)。

if I could loop this maybe如果我可以循环这个也许

function LoopTillLr() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('A2').activate();
  spreadsheet.getActiveRange().autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
};

Appreciate any help感谢任何帮助

在此处输入图像描述

If you only want to replicate the NAME values against variable LOCATION values then use this script:如果您只想针对变量 LOCATION 值复制 NAME 值,请使用此脚本:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSheet();
  var lastRow = ss.getDataRange().getLastRow();

  for (var i = 1; i < lastRow+1; i++) {
    if (ss.getRange(i,1).getValue() == "") {
      var value = ss.getRange(i-1,1).getValue();
      ss.getRange(i,1).setValue(value);
    }
  }
}

Ensure that A2 is not empty else the script will fail.确保 A2 不为空,否则脚本将失败。

If it is a lot of records, you can create a function and run it.如果记录很多,可以创建一个function并运行。 The following does this until the end of the sheet, so make sure to delete all the rows towards the end which you do not need or adjust the range in the 2nd row.以下内容一直执行到工作表末尾,因此请确保删除不需要的所有行或调整第二行中的范围。

function autoFillDown(){
  const range = SpreadsheetApp.getActiveSheet().getRange("A:A");
  const rows = range.getValues();
  let outputArray = [];

  rows.forEach( row => {
    // if it contains a name, leave it
    if( row[0].length > 1){ 
      outputArray.push( [row[0]] )       
    // otherwise replace it with the value above it
    } else {
      outputArray.push( [outputArray[outputArray.length-1]] );
    }    
  });  
  range.setValues( outputArray );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Apps 脚本:Sheets 表单数据操作,如果某些单元格为空,则删除行,同时保留某些列 - Google Apps Script: Sheets Forms Data Manipulation, Deleting Rows if Certain Cells are Blank, while Maintaining Certain Columns Google Apps 脚本不格式化 Google 表格中的行 - Google Apps Script not formatting rows in Google Sheets Google Sheets Apps 脚本自动填充公式语法错误 - Google Sheets Apps Script Autofill Formula Syntax Error 自动填充公式(跨电子表格运行) - Google 表格/应用程序脚本 - AutoFill Formula (running across spreadsheet) - Google Sheets / Apps Script 使用 Google Apps 脚本将数据保存在 Google 表格中 - Saving data in Google Sheets with Google Apps Script Google Apps 脚本多重自动填充 - Google Apps Script multiple autofill Apps Script API不会将数据粘贴到Google表格中 - Apps Script API not pasting data into Google Sheets 在 Apps Script 和 Google Sheets 中使用 ImportHTML 进行数据抓取 - Data Scraping With ImportHTML in Apps Script & Google Sheets 如何使用 Google Apps 脚本 select 谷歌表格上的所有行? - How to select all rows on Google Sheets using Google Apps Script? 谷歌表格谷歌应用程序脚本为所有行添加 VLOOKUP 函数 - Google Sheets google apps script add a VLOOKUP function for all rows
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM