質問編集履歴

2

変更

2021/01/30 05:39

投稿

HYoshitaka
HYoshitaka

スコア14

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,28 @@
5
5
  原因と解決策をご教示いただけますでしょうか。
6
6
 
7
7
  ```ここに言語を入力
8
+
9
+ function appendMenu(){
10
+
11
+ // メニューの追加
12
+
13
+ var menu = [
14
+
15
+ {name: '取得する', functionName: "getEvents"},
16
+
17
+ {name: '削除する', functionName: "removeRow"}
18
+
19
+
20
+
21
+ ];
22
+
23
+
24
+
25
+ SpreadsheetApp.getActiveSpreadsheet().addMenu("予定を取得", menu);
26
+
27
+ }
28
+
29
+
8
30
 
9
31
  function getEvents(){
10
32
 
@@ -26,7 +48,11 @@
26
48
 
27
49
  end.setMonth(end.getMonth()+1);
28
50
 
51
+
52
+
29
53
  var events = calendar.getEvents(from, end);
54
+
55
+ var rowIndex = 0;
30
56
 
31
57
  for (var i = 0; i < events.length; i++) {
32
58
 
@@ -34,29 +60,75 @@
34
60
 
35
61
  var title = events[i].getTitle();
36
62
 
37
- var startTime = events[i].getStartTime();
63
+
38
64
 
39
- var endTime = events[i].getEndTime();
65
+ var startTime = events[i].getStartTime();
40
66
 
41
- var duration = (endTime - startTime) /(1000*60)/(60);
67
+ var endTime = events[i].getEndTime();
42
68
 
43
- var detail = events[i].getDescription();
69
+ var duration = (endTime - startTime) /(1000*60)/(60);
44
70
 
45
- var location = events[i].getLocation();
71
+ var detail = events[i].getDescription();
46
72
 
47
- Logger.log(title);
73
+ var location = events[i].getLocation();
48
74
 
49
- if(title == "条件1"||title =="条件2"||title=="条件3"){
75
+ if (statTime == ""){
50
76
 
51
- sheet.getRange('B'+(i+40)).setValue(startTime).setNumberFormat('YYYY/MM/dd');
52
-
53
- sheet.getRange('C'+(i+40)).setValue(duration);
77
+ continue;
54
78
 
55
79
  }
56
80
 
81
+ Logger.log(title);
82
+
83
+ Logger.log(startTime);
84
+
85
+ if(title == "条件1"||title =="条件2"||title=="条件3"){
86
+
87
+ sheet.getRange('B'+(rowIndex+40)).setValue(startTime).setNumberFormat('YYYY/MM/dd');
88
+
89
+ sheet.getRange('C'+(rowIndex+40)).setValue(duration);
90
+
91
+ rowIndex = rowIndex+1;
92
+
93
+ }
94
+
95
+ }
96
+
97
+
98
+
99
+ function removeRow() {
100
+
101
+ //アクティブシートを取得
102
+
103
+ var sheet=SpreadsheetApp.getActiveSheet();
104
+
105
+ sheet.getLastRow();
106
+
107
+
108
+
109
+ // 最終行までループで回す
110
+
111
+ for(var row = 1; row <= sheet.getLastRow(); row++) {
112
+
113
+ var cell = sheet.getRange(row, 1);
114
+
115
+ if(cell.isBlank()){
116
+
117
+ sheet.deleteRow(row);
118
+
119
+ row-=1;
120
+
121
+ }
122
+
123
+ }
124
+
57
125
  }
58
126
 
127
+
128
+
59
- }
129
+ }
130
+
131
+
60
132
 
61
133
  ```
62
134
 
@@ -65,3 +137,15 @@
65
137
  取得した結果
66
138
 
67
139
  ![イメージ説明](1fa312f2b8e41e71a5f645f8b10bf5e3.png)
140
+
141
+
142
+
143
+ if (statTime == ""){
144
+
145
+ continue;
146
+
147
+ をコメントアウトした場合
148
+
149
+ ※1/30から下に必要ないデータまで取ってきてしまう。
150
+
151
+ ![イメージ説明](83e8618ca14dd8b8da1d70887d4c349c.png)

1

訂正

2021/01/30 05:39

投稿

HYoshitaka
HYoshitaka

スコア14

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  function getEvents(){
10
10
 
11
- var calendar = CalendarApp.getCalendarById('takatantakatan@gmail.com');
11
+ var calendar = CalendarApp.getCalendarById('ID');
12
12
 
13
13
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
14
14