回答編集履歴
3
answer
CHANGED
@@ -9,27 +9,21 @@
|
|
9
9
|
targetA1 = targetA1 || "A1:AA1";
|
10
10
|
const workingSheet = sheetName ? SpreadsheetApp.getActive().getSheetByName(sheetName) : SpreadsheetApp.getActiveSheet();
|
11
11
|
const sourceRange = workingSheet.getRange(sourceA1);
|
12
|
-
const
|
12
|
+
const keyColour = (sourceRange.getFontColor(), sourceRange.getBackground());
|
13
13
|
const designatedValue = sourceRange.getValue();
|
14
14
|
const targetRange = workingSheet.getRange(targetA1);
|
15
15
|
const targetColours = (targetRange.getFontColors(), targetRange.getBackgrounds());
|
16
|
-
|
17
16
|
const targetValues = targetRange.getValues();
|
18
|
-
targetRange.setValues(targetValues.map((r, i) => r.map((c, j) => targetColours[i][j] ===
|
17
|
+
targetRange.setValues(targetValues.map((r, i) => r.map((c, j) => targetColours[i][j] === keyColour && c !== '' ? designatedValue : c)));
|
19
18
|
|
20
19
|
}
|
21
20
|
```
|
22
21
|
|
23
22
|
・変えたところ
|
24
|
-
|
23
|
+
- keyColours -> keyColour に修正
|
24
|
+
- `?`の前に `&& c !== ''` を追加
|
25
|
+
- if ~ elseは削除
|
25
26
|
```diff
|
26
|
-
- const keyColour = (sourceRange.getFontColor(), sourceRange.getBackground());
|
27
|
-
+ const keyColours = (sourceRange.getFontColor(), sourceRange.getBackground());
|
28
|
-
```
|
29
|
-
|
30
|
-
(`?`の前に `&& c !== ''` を追加)
|
31
|
-
|
32
|
-
```diff
|
33
27
|
- targetRange.setValues(targetValues.map((r,i)=> r.map((c,j) => targetColours[i][j] === keyColours ?designatedValue:c)));
|
34
|
-
+ targetRange.setValues(targetValues.map((r, i) => r.map((c, j) => targetColours[i][j] ===
|
28
|
+
+ targetRange.setValues(targetValues.map((r, i) => r.map((c, j) => targetColours[i][j] === keyColour && c !== '' ? designatedValue : c)));
|
35
29
|
```
|
2
answer
CHANGED
@@ -21,6 +21,12 @@
|
|
21
21
|
```
|
22
22
|
|
23
23
|
・変えたところ
|
24
|
+
keyColour -> keyColours に修正
|
25
|
+
```diff
|
26
|
+
- const keyColour = (sourceRange.getFontColor(), sourceRange.getBackground());
|
27
|
+
+ const keyColours = (sourceRange.getFontColor(), sourceRange.getBackground());
|
28
|
+
```
|
29
|
+
|
24
30
|
(`?`の前に `&& c !== ''` を追加)
|
25
31
|
|
26
32
|
```diff
|
1
answer
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
下記のようにしてみてはいかがでしょうか。
|
2
2
|
```
|
3
3
|
const myFunction = () => {
|
4
|
-
q0A("A1", "
|
4
|
+
q0A("A1", "A1:AA1");
|
5
5
|
}
|
6
|
+
|
6
7
|
const q0A = (sourceA1, targetA1, sheetName) => {
|
7
8
|
sourceA1 = sourceA1 || "A1";
|
8
9
|
targetA1 = targetA1 || "A1:AA1";
|