回答編集履歴
1
コード追記
test
CHANGED
@@ -1,4 +1,26 @@
|
|
1
|
-
getValues()で一括取得、setFormulas()で一括設定するのはどうでしょうか?
|
1
|
+
~~getValues()で一括取得~~、setFormulas()で一括設定するのはどうでしょうか?
|
2
2
|
|
3
|
-
[getValues()リファレンス](https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues)
|
3
|
+
~~[getValues()リファレンス](https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues)~~
|
4
4
|
[setFormulas()リファレンス](https://developers.google.com/apps-script/reference/spreadsheet/range#setformulasformulas)
|
5
|
+
|
6
|
+
----
|
7
|
+
|
8
|
+
```gs
|
9
|
+
function myFunction7() {
|
10
|
+
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
|
11
|
+
var ss = spreadSheet.getSheets()[0];
|
12
|
+
var lastRow = ss.getLastRow();
|
13
|
+
|
14
|
+
// b列c列用のスプレッドシート関数設定
|
15
|
+
let bFormula = [];
|
16
|
+
let cFormula = [];
|
17
|
+
for (let i = 2; i <= lastRow; i++) {
|
18
|
+
bFormula.push(["=mid(A" + i +",1,4)"]);
|
19
|
+
cFormula.push(["=mid(A" + i +",5,2)"]);
|
20
|
+
}
|
21
|
+
|
22
|
+
// 2行目b列c列、最終行-1と1列に対して、スプレッドシート関数をセット
|
23
|
+
ss.getRange(2, 2, lastRow - 1, 1).setFormulas(bFormula);
|
24
|
+
ss.getRange(2, 3, lastRow - 1, 1).setFormulas(cFormula);
|
25
|
+
}
|
26
|
+
```
|