[英]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.