Google sheets 我怎样才能粘贴一个包含除值以外的所有内容的Google Sheets范围?
尝试复制一个范围,并在我的工作表末尾仅粘贴公式、格式和数据验证(无值),以便我可以在新粘贴的范围中输入新值。一切都正常,只是我不知道粘贴时如何排除值 这是我的密码:Google sheets 我怎样才能粘贴一个包含除值以外的所有内容的Google Sheets范围?,google-sheets,Google Sheets,尝试复制一个范围,并在我的工作表末尾仅粘贴公式、格式和数据验证(无值),以便我可以在新粘贴的范围中输入新值。一切都正常,只是我不知道粘贴时如何排除值 这是我的密码: function addCue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // copy the first cue range as template var copyCueRange = ss.getRange("A10:AA11"); // Find
function addCue() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// copy the first cue range as template
var copyCueRange = ss.getRange("A10:AA11");
// Find the end of the sheet and set pasteRange to match copyRange
var l = ss.getDataRange().getValues().length;
var pasteCueRange = ss.getRange( "A"+(l+1)+":AA"+(l+2) );
// This pastes all data, How do I paste without values?
copyCueRange.copyTo(pasteCueRange);
};
我对编码非常陌生,非常感谢您的帮助。谢谢。数据验证:
范围
类有两种方法用于获取和设置数据验证规则,setDataValidations()
和getDataValidations()
公式:与数据验证一样,Range
也有公式的get/set方法,setFormulas()
和getFormulas()
格式化:看起来像是Range.copyTo()
方法指定了一些选项。尝试使用formatOnly
附加参数
function addCue() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// copy the first cue range as template
var copyCueRange = ss.getRange("A10:AA11");
// Find the end of the sheet and set pasteRange to match copyRange
var l = ss.getDataRange().getValues().length;
var pasteCueRange = ss.getRange( "A"+(l+1)+":AA"+(l+2) );
//Getting data validation and formulas
var dataValidationRules = copyCueRange.getDataValidations();
var formulas = copyCueRange.getFormulas()
//Setting formatting, data validations, and formulas
copyCueRange.copyTo(pasteCueRange, {formatOnly:true});
pasteCueRange.setDataValidations(dataValidationRules);
pasteCueRange.setFormulas(formulas);
}
谢谢,巴康索达斯。不幸的是,将formatOnly作为附加参数添加只会导致粘贴格式。除了格式之外,我还希望复制和粘贴公式和数据验证。这样,用户可以在一些新粘贴的单元格中输入新值,工作表可以相应地进行计算。我又尝试了一次,这是您想要的功能吗?谢谢。是-pasteCueRange.setDataValidation(dataValidationRules)除外;应为pasteCueRange.setDataValidations(dataValidationRules);这样它就超过了这个范围。有了这个编辑,它就完美地工作了!!我现在了解到,这些元素中的每一个都必须分别复制和粘贴。再次感谢你!!(也不知道如何正确格式化这些注释中的代码-抱歉)哦,不。发现公式中的相对单元格引用在使用此脚本粘贴时没有更新。使用此脚本粘贴公式时,是否有方法让公式更新其单元格引用?对不起,我以前没注意到。非常感谢。我感谢你的帮助。