[英]Apply multiple font colors to the text in a single Google Sheets cell
[英]Google Sheets: Copying a cell with multiple font styles (colors) to another cell maintaining style
Range.copyTo模拟用户手动完成的正常复制粘贴。 它保留所有格式,包括富文本。
function copyAsCopiedByUser(){
const sh = SpreadsheetApp.getActive().getSheetByName("Sheet1")
sh.getRange("A1").copyTo(sh.getRange("B2"))
}
刚刚尝试了一些东西,它已经奏效了。 最后比我想象的要容易得多。
function copyWithFormat() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sourceRange = sheet.getRange("B1");
var targetRange = sheet.getRange("C1");
var sourceText = SpreadsheetApp.newRichTextValue();
sourceText = sourceRange.getValue().toString();
var sourceFormat = sourceRange.getRichTextValue();
targetRange.setValue(sourceText);
targetRange.setRichTextValue(sourceFormat);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.