仅复制和粘贴值和格式-Google脚本 [英] Copy and paste Value and Format Only - Google Script

查看:145
本文介绍了仅复制和粘贴值和格式-Google脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想复制和粘贴值和格式-而不是公式.

I'd like to copy and paste just values and format - not formula..

E.G(A1是动态文本):

E.G (A1 is a dynamic text):

A1 =测试"

A2 = = A1

我想使用一个脚本,该脚本在激活时将A2格式和文本(在这种情况下,将复制"test"-而不是"= a1")复制到A3.

I'd like to use a script that when activated it copy A2 format and text (in this case would copy "test" - not "=a1") to A3 .

我尝试使用"formatOnly:true,contentsOnly:true"-但它会继续复制公式.

I tried with "formatOnly:true , contentsOnly:true" - but it keep copying formula.

function Threebrow() {  
   var sheet2 = SpreadsheetApp.getActive().getSheetByName('c');
  sheet2.getRange("a2").copyTo(sheet2.getRange(sheet2.getLastRow()+1,1,1,7), {formatOnly:true , contentsOnly:true});
}

推荐答案

在此上下文中,公式也被视为内容. 下面的函数将A2的值和格式复制到第一列的最低行.

Formulas are also counted as content in this context. The below function copies value and format of A2 to the lowest row in the first column.

function Threebrow() {  
  var sheet2 = SpreadsheetApp.getActive().getSheetByName('c');
  var sourceRange = sheet2.getRange("a2");
  var targetRange = sheet2.getRange(sheet2.getLastRow()+1,1,1,1);
  targetRange.setValues(sourceRange.getValues());
  sourceRange.copyTo(targetRange, {formatOnly:true})
}

这篇关于仅复制和粘贴值和格式-Google脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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