简体   繁体   English

使用Google表格脚本移动过滤后的值(复制和粘贴值),而忽略列标题/标题

[英]Moving filtered values (copy and paste values) using google sheet script while ignoring the column heading / title

I would like to copy and paste VALUES only from source sheet to target sheet using google scripts. 我想使用Google脚本仅将VALUES从源表复制并粘贴到目标表。

I have filter applied in the column so I am only looking to copy the cells that are present / filtered (not all values). 我在该列中应用了过滤器,因此我只希望复制存在/已过滤的单元格(并非所有值)。

In the example that I have built, I have: 在我构建的示例中,我有:

Source sheet (copy values from): Sheet1 Target sheet (paste values to): Sheet2 源工作表(来自的复制值):Sheet1目标工作表(至的粘贴值):Sheet2

Sheet1 screenshot: Sheet1屏幕截图:

https://i.imgur.com/TySwfpb.jpg

Process / Steps: 流程/步骤:

When I select any particular color in "Fav_color" in column A..let's say "yellow". 当我在A列的“ Fav_color”中选择任何特定的颜色时,请说“黄色”。

Now, Members are filtered accordingly. 现在,将对成员进行相应过滤。

On the button click, I want my google script function to run that copies the filtered Member Names and paste it in Sheet2. 在按钮上单击,我希望我的Google脚本功能运行,该功能将复制过滤的成员名称并将其粘贴到Sheet2中。

Problem : In Sheet 2: I am getting column heading / title as well "Member Name" while I only want member names (not the actual column name). 问题 :在工作表2中:我只需要成员名称(而不是实际的列名称)时也得到列标题/标题以及“成员名称”。

I do know the problem as in my code, I am copying complete B column but I do not know how to exclude column heading / title. 我确实知道我的代码中的问题,我正在复制完整的B列,但不知道如何排除列标题/标题。

function transfer() {
 var sss = SpreadsheetApp.getActiveSpreadsheet();
 var ss = sss.getSheetByName('Sheet1'); 
 var range = ss.getRange('A1:A'); 
 var data = range.getValues();

 var tss = SpreadsheetApp.getActiveSpreadsheet();
 var ts = tss.getSheetByName('Sheet2');
 ts.getRange('A:A').clearContent();

  ts.getRange('A:A').clearContent();
  ss.getRange("B:B").copyTo(ts.getRange("A2"), {contentsOnly:true});

}

Issue: 问题:

If you use, 如果您使用,

ss.getRange("B2:B").copyTo(ts.getRange("A2"), {contentsOnly:true});

it always bring the value from B2 cell even if it is not visible in filtered results 即使它在过滤结果中不可见,也总是从B2单元格中获取值

Solution: 解:

You can get the first non-filtered row number using Sheet#isRowHiddenByFilter 您可以使用Sheet#isRowHiddenByFilter获取第一个未过滤的行号

Snippet: 片段:

function copycolB() {
  var ss = SpreadsheetApp.getActive();
  var sourceSheet = ss.getSheetByName('Sheet1');
  var targetSheet = ss.getSheetByName('Sheet2');
  for(var row = 2; sourceSheet.isRowHiddenByFilter(row); ++row);//get first  visible row from row2
  var sourceRange = sourceSheet.getRange('B' + row + ':B');
  sourceRange.copyTo(
    targetSheet.getRange('A2'),
    {contentsOnly:true});
}

References: 参考文献:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Google 脚本从 1 个 Google 工作表中复制特定值并粘贴到另一个工作表? - How can I copy specific values from 1 Google Sheet and paste to another Sheet using Google Script? 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? google app脚本将值!= 0复制到新列中 - google app script copy values !=0 into new column Google 工作表脚本 - 将行值复制到最后使用的行 - Google sheet script - copy row values to last used row 将背景颜色从一列复制/粘贴到具有匹配值的列中的另一张工作表 - Copy / paste background color from one column to another sheet in a column with matched values Javascript循环浏览每个Google表格标签,并将所有单元格复制并粘贴为仅值 - Javascript to cycle through each google sheet tab and copy and paste all cells as values only 通过Apps脚本在Google表格列中写入值 - Writing the values in Google Sheet column via Apps Script Google脚本可复制列的值并在电子表格中插入新列 - Google Script to copy the values of a column and insert a new column in spreadsheet Google脚本:如何将范围复制并粘贴到不为空的行中的新表中 - Google Script: How to copy and paste range to a new sheet on a row that is not empty 如果值存在于工作表 1 和工作表 2 中,则复制行并将其粘贴到工作表 3。Google 表格。 Google Apps 脚本 - Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM