在Google应用中将不连续的列从一个电子表格复制到另一个电子表格 [英] Non-contiguous column copy from one spreadsheet to another in google apps
问题描述
我如何格式化非连续列以复制到其他工作表?我知道(感谢塞尔),你可以做以下连续的列!
How would I format non-contiguous columns to be copied to another sheet? I know (thanks Serge) that you can do contiguous columns with the following!
.getRange("A2:C")
说我需要做A列,C,K,AD,BB例如。
say I need to do column A, C, K, AD, BB for example.
有没有比分配所有需要不同变量的所有列更简单的方法,将它们全部单独取出并放入需要的表单中?
Is there a simpler way than assigning all columns you need different variables, getting them all individually, and putting them in the sheet you need?
感谢您的帮助!
推荐答案
可能并不简单,但我会说更好的性能,使用<$包含所需的所有列c $ c> .get(Data)Range()。getValues(),使用Javascript剥离数组以仅使用所需的列,并使用 setValues() / code>将这些值粘贴到一次打击中:
Probably not simpler, but I would say better performance, to get one big range encompassing all the columns you need with .get(Data)Range().getValues()
, use Javascript to strip down the array to only the columns you need, and use setValues()
to paste the values in one hit:
function copyValuesOnly() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var values = ss.getSheetByName('Source').getDataRange().getValues();
values.shift(); //remove header row
var columns = [0, 2, 10, 29, 53]; //array of zero-based indices of required columns
var output = [];
for (var i = 0, length = values.length; i < length; i++) {
output[i] = [];
for (var j = 0, width = columns.length; j < width; j++) {
output[i][j] = values[i][columns[j]];
}
}
ss.getSheetByName('Destination').getRange(2, 1, length, width).setValues(output);
}
问题在于您需要复制格式和公式,其中如上所述,最好的选择可能是复制粘贴每一列。
The issue would be if you required copying formats and formulae as well, in which case the best option might be copy-pasting each column individually, as you mentioned.
这篇关于在Google应用中将不连续的列从一个电子表格复制到另一个电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!