![](/img/trans.png)
[英]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.