回答編集履歴

2

a

2019/10/27 14:01

投稿

papinianus
papinianus

スコア12705

test CHANGED
@@ -32,9 +32,9 @@
32
32
 
33
33
  const messages = GmailApp.getMessagesForThreads(threads)
34
34
 
35
- .map(function(mth){ return [ mth.map(messageToArray)];});
35
+ .reduce(function(a,c){ return a.concat(c.map(messageToArray));},[]);
36
36
 
37
- shee.getRange(sheet.getLastRow() + 1, 1, messages.length, 12).setValues(messages);
37
+ sheet.getRange(sheet.getLastRow() + 1, 1, messages.length, 12).setValues(messages);
38
38
 
39
39
  }
40
40
 

1

a

2019/10/27 14:01

投稿

papinianus
papinianus

スコア12705

test CHANGED
@@ -15,3 +15,73 @@
15
15
 
16
16
 
17
17
  lastRowを得ているのですから(ここで得るのはどうかと思いますが)、`Range.setValues`で書き込めば書式は維持されると想像します。
18
+
19
+
20
+
21
+ ```javascript
22
+
23
+ function myFunction() {
24
+
25
+ const sheet = SpreadsheetApp.getActiveSheet();
26
+
27
+
28
+
29
+ const query = 'label:(00_hp問合せ-10-23資料dw)';
30
+
31
+ const threads = GmailApp.search(query, 0, 30);
32
+
33
+ const messages = GmailApp.getMessagesForThreads(threads)
34
+
35
+ .map(function(mth){ return [ mth.map(messageToArray)];});
36
+
37
+ shee.getRange(sheet.getLastRow() + 1, 1, messages.length, 12).setValues(messages);
38
+
39
+ }
40
+
41
+
42
+
43
+ function messageToArray(m) {
44
+
45
+ const body = m.getPlainBody();
46
+
47
+ return [
48
+
49
+ m.getDate(),
50
+
51
+ m.getFrom(),
52
+
53
+ fetchData(body, '会社名:', '\r'),
54
+
55
+ fetchData(body, 'お名前(姓):', '\r'),
56
+
57
+ fetchData(body, 'お名前(名):', '\r'),
58
+
59
+ fetchData(body, '電話番号:', '\r'),
60
+
61
+ fetchData(body, 'メールアドレス:', '\r'),
62
+
63
+ fetchData(body, '携帯電話:', '\r'),
64
+
65
+ fetchData(body, '登録者:', '\r'),
66
+
67
+ fetchData(body, '顧客主担当:', '\r'),
68
+
69
+ fetchData(body, '担当エリア:', '\r'),
70
+
71
+ fetchData(body, '資料:', '\r'),
72
+
73
+ ];
74
+
75
+ }
76
+
77
+
78
+
79
+ function fetchData(str, pre, suf) {
80
+
81
+ const res = str.match(new RegExp(pre + '(.*?)' + suf));
82
+
83
+ return res === null ? '' : res[1];
84
+
85
+ }
86
+
87
+ ```