简体   繁体   English

如何从Google电子表格中的另一张纸上获取带有文本的彩色单元格?

[英]How to get Colored cell with text from another sheet in google spreadsheet?

How to get Colored cell with text from another sheet in google spreadsheet? 如何从Google电子表格中的另一张纸上获取带有文本的彩色单元格?

Hi, I have 2 sheets and I'm trying to get the colored cell with text from sheet 1 to sheet 2. 嗨,我有2张纸,我正在尝试从第一张纸到第二张纸来获取带有文本的彩色单元格。

Can someone help me, please? 有人能帮助我吗?

Example: 例:

In sheet 1 i put a data in Column 1 Row 1 and then colored it with yellow at the same time it will appear in sheet 2 Column 1 Row 1. 在工作表1中,我将数据放在第1列第1行中,然后同时将其涂成黄色,同时它将出现在工作表2的第1列第1行中。

Copy everything 复制所有内容

If you want to copy everything, including Range values, colour, background-colour, etc - use the simple copyTo() method. 如果要复制所有内容,包括Range值,颜色,背景色等,请使用简单的copyTo()方法。 Just remember that Range dimensions should be equal (ofc, you can always add handling to account for that). 请记住, Range尺寸应相等(ofc,您可以随时添加处理内容)。

/**
 * Copies all;
 * @param {Range} source copy from range;
 * @param {Range} target copy to range;
 */
function copyAll(source,target) {
  source.copyTo(target);
}

Conditional copy 有条件的复制

If you wish to copy only specific properties of the Range , the abovementioned copyTo() method can be invoked with CopyPasteType enum, like this (please, note that due to conflict with two-arg invocation copyTo(range,options) , transpose arg is necessary - you can hardcode it inside the function if you don't expect orientation changes): 如果您只想复制Range特定属性,可以使用CopyPasteType枚举来调用上述copyTo()方法,如下所示(请注意,由于与两个参数调用copyTo(range,options)冲突,所以转置arg为必要-如果您不希望更改方向,则可以在函数内部对其进行硬编码):

/**
 * Copies only specific props;
 * @param {Range} source copy from range;
 * @param {Range} target copy to range;
 * @param {String} type enum CopyPasteType;
 * @param {Boolean} transposed change orientation or not;
 */
function copyConditional(source,target,type,transposed) {
  var t = SpreadsheetApp.CopyPasteType[type];
  source.copyTo(target,t,transposed); //if transpose is not specified, will be treated as copyTo(destination,options)!;
}

Copy via getter and setter 通过getter和setter复制

For example, use the getBackgrounds() and setBackgrounds() respectively (there are a lot of other getter-setter methods you can use separately instead of the copyTo() , see Range reference in useful links). 例如,分别使用getBackgrounds()setBackgrounds() (还有很多其他的getter-setter方法可以代替copyTo()单独使用,请参见有用链接中的Range引用)。

/**
 * Copies background color;
 * @param {Range} source copy from range;
 * @param {Range} target copy to range;
 */
function copyColor(source,target) {
  var color = source.getBackgrounds();  
  target.setBackgrounds(color);
}

Useful links 有用的链接

  1. copyTo() reference ; copyTo() 参考
  2. CopyPasteType enum reference ; CopyPasteType枚举引用
  3. Range class reference ; Range参考 ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Google Spreadsheet单元格获取文本? - How to get the text from a Google Spreadsheet cell? Google Spreadsheet-如何将单元格数据从一张工作表复制到另一张工作表中的单元格? - Google Spreadsheet - How to copy cell data from one sheet to a cell in another sheet? 如何制作一个按钮以跳到Google Spreadsheet中另一个工作表中的特定单元格? - How to make a button to jump to a specific cell in another sheet in Google Spreadsheet? 如何将 Google 电子表格的特定表格和 CSV 值保存在同一电子表格中另一表格的单个单元格中? - How to save a specific sheet of Google Spreadsheet a CSV values in a single cell of another sheet within the same Spreadsheet? Google Spreadsheet-脚本,每天在特定时间将单元格从一张工作表复制到另一张工作表 - Google Spreadsheet - Scripts, copy cell from one sheet to another sheet EVERYDAY at a specific time 将 ImportRange 生成的 Google 电子表格单元格值自动传输到另一个工作表和单元格 - Transfer Google Spreadsheet Cell Value generated from ImportRange to another sheet and cell automatically Google Script:如何将CopyRows从一个工作表复制到另一个工作表 - Google Script: How to CopyRows from one sheet to another spreadsheet 从Google电子表格中获取所有工作表标签名称的列表,并将名称放入另一个电子表格中 - Get a list of all the sheet tab names from a Google spreadsheet and put the names into another spreadsheet 从谷歌表格单元格获取文本到谷歌文档 - Get text from google sheet cell to a google doc 我无法使用Apps脚本在Google电子表格中使用一个表格中的单元格值到另一个表格中的单元格值 - I cant use a cell value from one sheet to another in google spreadsheet using apps script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM