简体   繁体   English

Google表格:将具有多种字体styles(颜色)的单元格复制到另一个保持样式的单元格

[英]Google Sheets: Copying a cell with multiple font styles (colors) to another cell maintaining style

How can I copy a cell with different font colors to another cell?如何将具有不同字体 colors 的单元格复制到另一个单元格? Basically want to perform a standard copy-paste maintaining styles of the copied cell... below are examples of source cells:基本上想要执行一个标准的复制粘贴来维护复制单元格的 styles ......下面是源单元格的示例:

在此处输入图像描述

The format is important as it gives more info based on the different color codes.格式很重要,因为它会根据不同的颜色代码提供更多信息。

Range.copyTo emulates a normal copy paste done manually by a user. Range.copyTo模拟用户手动完成的正常复制粘贴。 It preserves all formatting including rich text.它保留所有格式,包括富文本。

function copyAsCopiedByUser(){
  const sh = SpreadsheetApp.getActive().getSheetByName("Sheet1")
  sh.getRange("A1").copyTo(sh.getRange("B2"))
}

Have just tried something and it has worked.刚刚尝试了一些东西,它已经奏效了。 Much easier than I thought in the end.最后比我想象的要容易得多。

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.

相关问题 将多种字体颜色应用于单个 Google 表格单元格中的文本 - Apply multiple font colors to the text in a single Google Sheets cell 谷歌表格,两种字体大小一个单元格 - Google Sheets, Two Font Sizes One Cell 如何在 Google Sheets 中获取单元格的字体颜色? - How to get font color of cell in Google Sheets? 以编程方式检索Google表格单元格边框样式 - Retrieving Google Sheets cell border style programmatically Google表格根据单元格值从一张表格复制和粘贴到另一张表格 - Google Sheets Copying and Pasting from one sheet to another based on cell value Google脚本将单元格的一部分复制到另一个工作表 - Google Script Copying part of a cell to another sheet Google表格可以将一个单元格更改为另一个单元格 - Google Sheets change one cell from another Google表格:“单击”时,用另一个单元格内容替换单元格内容吗? - Google Sheets: Replace cell contents with another cell contents when “Clicked”? 在 Google Sheets 中,是否可以将活动单元格的内容显示到另一个单元格? - In Google Sheets, is it possible to display the contents of the active cell to another cell? 谷歌表格复制一个单元格并粘贴到另一个单元格 - Google Sheets Copy one Cell and paste into another Cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM