将范围从一个电子表格复制到另一个电子表格 [英] Copy a range from one spreadsheet to another

查看:68
本文介绍了将范围从一个电子表格复制到另一个电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个数组的内容从一张工作表(其中通过迭代并推动用户选择的列的选择项创建数组)复制到另一张电子表格中的另一张工作表中.

I am attempting to copy the contents of an array from one sheet (where the array is created by iterating through and pushing select items for the column of the user's choosing) to a different sheet in a different spreadsheet.

关于如何将一个范围从一个电子表格导入到另一个电子表格,我遇到了许多问题和答案,但是它们都不对我有用(都返回了错误很抱歉,发生服务器错误.请请稍候,然后重试.")我也尝试过'copyTo',但没有成功.

I have come across a number of questions and answers on how to import a range from one spreadsheet to another, but none of them has worked for me (all returning the error "We're sorry, a server error occurred. Please wait a bit and try again.") I've tried 'copyTo' as well, with no success.

这是我当前正在使用的代码.我哪里出问题了?

Here is the code I'm using currently. Where have I gone wrong??

function copyToTrix(featureList) {

  featureList = featureList.getValues();

  var tss = SpreadsheetApp.openById("0AtX9IYFZ..."); //define active trix as target 

var ts = tss.getSheetByName("US");          //define sheet in target trix

var newRange = ts.getRange("DA12:DA25");    //define target range

 newRange.setValues(featureList);  //set values in target range to items in featureList

Browser.msgBox('copied');
}

推荐答案

事实证明,GAS在使用setValues()函数时遇到了麻烦.不能完全使用它,所以我最终不得不使用setValue(). (设置值仅允许您一次在一个单元格中操作):

It turns out the GAS is having trouble with the setValues() function. It wasn't working to take a full range, so I ended up having to use setValue() instead. (Set value only allows you to operate in one cell at a time):

var tss = SpreadsheetApp.openById("0AtX9IYFZ9KkbdHg4TUdqYVppTTU5OENpb04tWTdNbHc");
var ts = tss.getSheetByName("US");
for (var i = 0; i < featureList.length; i++) {
var position = i + 12;
ts.setActiveCell("B" + position).setValue(featureList[i]);

这篇关于将范围从一个电子表格复制到另一个电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆