当我使用脚本导出数据时,为什么我的数据会在Google表格中重复出现? [英] Why does my data get duplicated in Google sheets when I use a script to export it?
问题描述
我正在研究一些代码,这些代码会将工作表中的数据导出到工作簿中,到目前为止它工作得很好,但我遇到了问题,因为导出数据时数据会重复。任何帮助你将不胜感激。这是我到目前为止的代码
函数CopyDataToNewFile(){
var sss = SpreadsheetApp.openById('didnt post this'); // sss =源电子表格
var ss = sss.getSheetByName('Sheet1'); // ss =源表
//获取全部数据
var SRange = ss.getDataRange();
//获取A1识别范围的符号
var A1Range = SRange.getA1Notation();
//获取范围内的数据值
var SData = SRange。 getValues();
var tss = SpreadsheetApp.openById('这是正确的,但我没有把它放在这篇文章上。'); // tss =目标电子表格
var ts = tss.getSheetByName('Results'); // ts =目标表
ts.clear({contentsOnly:true});
//将目标范围设置为源数据的值
ts.getRange(A1Range).setValues(SData);
ts.getRange(ts.getLastRow()+ 1,1,SData.length,SData [0] .length)。 setValues(SData);
我尝试过:
我不知道该尝试我接下来没有编码训练,我刚刚摆弄。
Quote:
ts.getRange(A1Range).setValues(SData);
ts.getRange(ts.getLastRow()+ 1,1,SData.length,SData [0] .length)。setValues(SData);
删除第二行。您在两个不同的范围内调用setValues
,即插入两个源数据副本。
ts.getRange (A1Range).setValues(SDATA);
//删除此行:
// ts.getRange(ts.getLastRow()+ 1,1,SData.length,SData [0] .length)。setValues(SData) ;
I'm working on some code that will export data from a sheet into a workbook and so far its working sort of well but i'm running into issues because the data is duplicating when I export it. Any help you would be greatly appreciated. Here is my code so far
function CopyDataToNewFile() {
var sss = SpreadsheetApp.openById('didnt post this'); // sss = source spreadsheet
var ss = sss.getSheetByName('Sheet1'); // ss = source sheet
//Get full range of data
var SRange = ss.getDataRange();
//get A1 notation identifying the range
var A1Range = SRange.getA1Notation();
//get the data values in range
var SData = SRange.getValues();
var tss = SpreadsheetApp.openById('It is correct but i did not put it on this post.'); // tss = target spreadsheet
var ts = tss.getSheetByName('Results'); // ts = target sheet
ts.clear({contentsOnly: true});
//set the target range to the values of the source data
ts.getRange(A1Range).setValues(SData);
ts.getRange(ts.getLastRow()+1,1,SData.length,SData[0].length).setValues(SData);
What I have tried:
I don't know what to try I have next to no training in coding, i have just been fiddling around.
Quote:
ts.getRange(A1Range).setValues(SData); ts.getRange(ts.getLastRow()+1,1,SData.length,SData[0].length).setValues(SData);
Remove the second of those lines. You're callingsetValues
on two different ranges, which is inserting two copies of the source data.
ts.getRange(A1Range).setValues(SData); // Remove this line: // ts.getRange(ts.getLastRow()+1,1,SData.length,SData[0].length).setValues(SData);
这篇关于当我使用脚本导出数据时,为什么我的数据会在Google表格中重复出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!