[英]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 有用的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.