简体   繁体   English

Google 工作表脚本将数据集从一张工作表复制到另一张工作表的顶部(仅限值)

[英]Google sheets script copy data sets from one sheet to another (values only) at the top of the sheet

I have a task that requires that I move data from one sheet to another (much like a log).我有一项任务需要将数据从一张纸移动到另一张纸(很像日志)。 I prefer that the each time more data is added it be to the top of the log sheet.我更喜欢每次添加更多数据时将其添加到日志表的顶部。 Lets say sheet "index generation" has data in the first 3 rows.假设工作表“索引生成”在前 3 行中有数据。 The three rows from "index generation" needs to be added to the top of sheet "index" without over-righting or having more than just 3 rows added. “索引生成”中的三行需要添加到工作表“索引”的顶部,而不会过度调整或添加超过 3 行。

Thanks for any help you might be able to offer!感谢您提供的任何帮助!

Here is the current status but it has cannot find function getActiveSpreadSheet in object SpreadsheetApp.这是当前状态,但它在对象 SpreadsheetApp 中找不到函数 getActiveSpreadSheet。

function IndexCopy() {
  var app = SpreadsheetApp;
  var ss = app.getActiveSpreadSheet();
  var indexGen = ss.getSheetByName('Index Generation')
  var index = ss.getSheetByName('Index');
  var Rows = indexGen.range.getValues();
  var array = sheet.range.getValues();
array.splice(0, 0, Rows);
  // add three rows to sheet.range then 
index.range.setValues(array)
};

try something like this:尝试这样的事情:

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Custom Menu')
      .addItem('First item', 'indexCopy')
      .addToUi();
}

function indexCopy()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var src = ss.getSheetByName('source');
  var dest = ss.getSheetByName('destination');
  var srcDatas = src.getDataRange().getValues();
  var destDatas = dest.getDataRange().getValues();
  var i = srcDatas.length - 1
  while (i >= 0)
    destDatas.splice(1, 0, srcDatas[i--]);
  dest.getRange("A1:B" + destDatas.length).setValues(destDatas);
}

look at this documentation看看这个文档

Give this a try: You first have to select the number of rows you want to move from the Index Generation Sheet and then run this function.试一试:您首先必须从索引生成表中选择要移动的行数,然后运行此函数。

function IndexCopy() {
  var ss=SpreadsheetApp.getActive();
  var igSht=ss.getSheetByName('Index Generation');
  var igRg=igSht.getActiveRange();
  var igA=igRg.getValues();
  var iSht=ss.getSheetByName('Index');
  for(var i=0;i<igA.length;i++){
    iSht.insertRowBefore(1);
    iSht.getRange(1,1,1,igA[i].length).setValues([igA[i]]);
  }
  igSht.deleteRows(1, igA.length);
}

暂无
暂无

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

相关问题 将数据从一张纸复制到另一张 - Google Script - Copy Data from one sheet to another - Google Script Google 工作表应用程序脚本 - 根据循环条件将数据从一张工作表复制到另一张工作表 - Google sheet app script - Copy data from one sheet to another based on condition with loop 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet 根据条件将单元格值从一个Google工作表复制到另一个 - Copy cell values from one google sheet to another based on condition 如何使用 Google 脚本从 1 个 Google 工作表中复制特定值并粘贴到另一个工作表? - How can I copy specific values from 1 Google Sheet and paste to another Sheet using Google Script? 通过for循环谷歌表格脚本将行复制到另一张表格 - Copy row to another sheet via for loop google sheets script 将范围从一个工作表复制到Google工作表中的另一个工作表 - Copy a range from one sheet to another in google sheet 谷歌脚本将数据从工作表 1 复制到第一个空行工作表 2 - google script copy data from sheet 1 to first empty row sheet 2 Google Apps脚本-从另一个工作表导入工作表值 - Google apps script - Importing sheet values from another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM