質問編集履歴

1

コードを追加させていただきました。このコードで時間が10秒以上かかってしまうのは、スプレッドシート内でcountifやvlookup等を使っているのがよくないのでしょうか。

2020/03/04 11:23

投稿

tetsu911
tetsu911

スコア12

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,165 @@
15
15
 
16
16
 
17
17
  ![イメージ説明](806726a155eef27deb3c10cdf636c49b.png)
18
+
19
+
20
+
21
+ ```GAS
22
+
23
+ function doGet(e) {
24
+
25
+ if (!e.parameter.page) {
26
+
27
+ return HtmlService.createTemplateFromFile('index').evaluate();
28
+
29
+ }
30
+
31
+ return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();
32
+
33
+ }
34
+
35
+
36
+
37
+ var id = "";
38
+
39
+ var spreadSheet = SpreadsheetApp.openById(id);
40
+
41
+ var t=HtmlService.createTemplateFromFile("index");
42
+
43
+
44
+
45
+ //それぞれのシートを取得
46
+
47
+ var sheet = spreadSheet.getSheetByName("Data");
48
+
49
+ var sheet2 = spreadSheet.getSheetByName("Phone");
50
+
51
+ var sheet3 = spreadSheet.getSheetByName("Warning");
52
+
53
+
54
+
55
+ //それぞれのシートの最終行を取得
56
+
57
+ var last_row = sheet.getLastRow();
58
+
59
+ var last_row2 = sheet2.getLastRow();
60
+
61
+
62
+
63
+
64
+
65
+ //それぞれのシートの数値を取得
66
+
67
+ var ary = sheet.getRange(2,1,last_row,5).getValues();
68
+
69
+ var ary2 = sheet2.getRange(2,1,last_row2,8).getValues();
70
+
71
+ var last_row3 = sheet3.getLastRow();
72
+
73
+ var ary3 = sheet3.getRange(1,1,last_row3,2).getValues();
74
+
75
+
76
+
77
+ for (var i = 0; i < last_row; i++){
78
+
79
+ if(isNaN(ary[i][1]) || ary[i][1] > 156 || ary[i][1] == ""){
80
+
81
+ ary[i][1] = 170;
82
+
83
+ }}
84
+
85
+
86
+
87
+ //HMTLで変数を使用できるようにする
88
+
89
+ t.ary = ary;
90
+
91
+ t.last_row = last_row;
92
+
93
+ t.ary2 = ary2;
94
+
95
+ t.last_row2 = last_row2;
96
+
97
+ t.ary3 = ary3;
98
+
99
+ t.last_row3 = last_row3;
100
+
101
+
102
+
103
+ Javascript
104
+
105
+ function firstscript(){
106
+
107
+
108
+
109
+ <? for(var j = 1; j < 41; j++){ ?>
110
+
111
+ var target = document.getElementById("w"+<?= j ?>);
112
+
113
+
114
+
115
+ if(<?= ary3[j][1] ?> == "予約済"){
116
+
117
+ target.innerHTML = "<?= ary3[j][0] ?>";
118
+
119
+ target.style.backgroundColor = "lightpink";
120
+
121
+
122
+
123
+ }else if(<?= ary3[j][1] ?> == "-"){
124
+
125
+ target.style.backgroundColor = "#98FB98";
126
+
127
+ target.innerHTML = "<?= ary3[j][0] ?>";
128
+
129
+
130
+
131
+ }
132
+
133
+ <? }; ?>
134
+
135
+
136
+
137
+ <? for(var i = 0;i < last_row; i++){ ?>
138
+
139
+ var target = document.getElementById("cb"+<?= ary[i][1] ?>);
140
+
141
+
142
+
143
+ if(<?= ary[i][2] ?> == ""){
144
+
145
+ target.style.backgroundColor = "white";
146
+
147
+ target.innerHTML = "<?= ary[i][1] ?>";
148
+
149
+ }else if(<?= ary[i][3] ?> == "予約済"){
150
+
151
+ target.style.backgroundColor = "lightyellow";
152
+
153
+ target.innerHTML = "<?= ary[i][1] ?> <?= ary[i][2] ?>";
154
+
155
+ }else if(<?= ary[i][4] ?> < 1){
156
+
157
+ target.style.backgroundColor = "#aaaaaa";
158
+
159
+ target.innerHTML = "<?= ary[i][1] ?> <?= ary[i][2] ?>";
160
+
161
+ }else{
162
+
163
+ target.style.backgroundColor = "#98FB98";
164
+
165
+ target.innerHTML = "<?= ary[i][1] ?> <?= ary[i][2] ?>";
166
+
167
+ }
168
+
169
+ <? }; ?>
170
+
171
+ }
172
+
173
+
174
+
175
+ window.onload = firstscript;
176
+
177
+ </script>
178
+
179
+ ```