[英]Is it possible to append to the next column horizontally in google sheets?
I currently have this script.我目前有这个脚本。 I works fine, however, I would prefer if it appended to the next column horizontally each time a choose to append.我工作得很好,但是,如果每次选择 append 时,我希望它水平附加到下一列。 Right now it appends after the last row.现在它附加在最后一行之后。 Please be very specific about what needs changing.请非常具体地说明需要更改的内容。 Thanks!谢谢!
function myFunction() {
var ss = SpreadsheetApp.openById("1aACg8M89LLxILIvUqWT2ZnrykF8e3BkIiamj2NhKrmc")
var sheet = ss.getSheetByName("Framsida");
var data = sheet.getRange(2, 3, 25, 1).getValues();
for (var i = 0; i < data.length; i++) {
Logger.log(data[i][0]);
Logger.log(data[i][1]);
}
var row= sheet.getLastRow();
Logger.log(row);
Logger.log(data);
var temp = data
for (i in temp){
var write = temp[i]
if (row >=10) {ss.getSheetByName("Archive").appendRow(write)};
}
ss.getSheetByName("Framsida").getRange(2, 3, 25, 1).clear();
}
You want to retrieve the values from the cells of "C2:C26" on the sheet "Framsida", and want to put the values to the next column of the last column on the sheet "Archive".您想从工作表“Framsida”上的“C2:C26”单元格中检索值,并希望将值放在工作表“存档”上最后一列的下一列。
In order to retrieve the last column of the sheet, please use getLastColumn()
.为了检索工作表的最后一列,请使用getLastColumn()
。 Here, I would like to propose 2 patterns for achieving your goal.在这里,我想提出 2 种模式来实现您的目标。
In this pattern, getValues
and setValues
are used.在此模式中,使用getValues
和setValues
。
function myFunction() {
var ss = SpreadsheetApp.openById("1aACg8M89LLxILIvUqWT2ZnrykF8e3BkIiamj2NhKrmc")
var srcSheet = ss.getSheetByName("Framsida"); // <--- Modified
var srcRange = srcSheet.getRange(2, 3, 25, 1);
var data = srcRange.getValues();
var dstSheet = ss.getSheetByName("Archive");
dstSheet.getRange(2, dstSheet.getLastColumn() + 1, data.length, 1).setValues(data);
srcRange.clear();
}
In this pattern, copyTo
is used.在此模式中,使用了copyTo
。
function myFunction() {
var ss = SpreadsheetApp.openById("1aACg8M89LLxILIvUqWT2ZnrykF8e3BkIiamj2NhKrmc")
var srcSheet = ss.getSheetByName("Framsida"); // <--- Modified
var srcRange = srcSheet.getRange(2, 3, 25, 1);
var dstSheet = ss.getSheetByName("Archive");
srcRange.copyTo(dstSheet.getRange(2, dstSheet.getLastColumn() + 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES);
srcRange.clear();
}
srcRange.copyTo(dstSheet.getRange(2, dstSheet.getLastColumn() + 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES);
当srcRange.copyTo(dstSheet.getRange(2, dstSheet.getLastColumn() + 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES);
is modified to srcRange.copyTo(dstSheet.getRange(2, dstSheet.getLastColumn() + 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES, true);
修改为srcRange.copyTo(dstSheet.getRange(2, dstSheet.getLastColumn() + 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES, true);
, the values are put by transposing. , 这些值是通过转置放置的。
appended to the next column horizontally
means that you want to horizontally put the values from "C2:C26" to the last column by transposing, please test this.如果appended to the next column horizontally
意味着您想通过转置将“C2:C26”中的值水平放置到最后一列,请测试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.