質問編集履歴

4

修正

2020/10/08 09:31

投稿

3939TJ55
3939TJ55

スコア109

test CHANGED
File without changes
test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  所定フォルダ内の「Book.xlsm」を指定して読み込む
40
40
 
41
- filepath = 'C:/Users/'
41
+ filepath = 'C:/Users/Desktop/python lesson/メール保存/Outlook_Book2.xlsx'
42
42
 
43
43
  wb = load_workbook(filename=filepath)
44
44
 
@@ -76,7 +76,7 @@
76
76
 
77
77
  foldermake = foldermake.replace(" ","-")
78
78
 
79
- newfolder_path = 'C:/Users/'+foldermake
79
+ newfolder_path = 'C:/Users/Desktop/python lesson/メール保存/Outlook_'+foldermake
80
80
 
81
81
  os.makedirs(newfolder_path)
82
82
 
@@ -136,7 +136,7 @@
136
136
 
137
137
  Outlook_Book2.xlsx」として所定のフォルダに保存
138
138
 
139
- newfilepath = 'C:/Users/'
139
+ newfilepath = ''C:/Users/Desktop/python lesson/メール保存/Outlook_Book2.xlsx'
140
140
 
141
141
  wb.save(newfilepath)
142
142
 

3

インデント修正

2020/10/08 09:31

投稿

3939TJ55
3939TJ55

スコア109

test CHANGED
File without changes
test CHANGED
@@ -88,49 +88,49 @@
88
88
 
89
89
  for message in messages:
90
90
 
91
- RT = message.ReceivedTime
91
+   RT = message.ReceivedTime
92
92
 
93
- hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
93
+   hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
94
94
 
95
- if startdate <= hiduketime <= enddate:
95
+   if startdate <= hiduketime <= enddate:
96
96
 
97
- ws1.cell(row=7+a, column=1).value = a+1
97
+     ws1.cell(row=7+a, column=1).value = a+1
98
98
 
99
- ws1.cell(row=7+a, column=2).value = str(message.Subject)
99
+     ws1.cell(row=7+a, column=2).value = str(message.Subject)
100
100
 
101
- ws1.cell(row=7+a, column=3).value = hiduketime
101
+     ws1.cell(row=7+a, column=3).value = hiduketime
102
102
 
103
- ws1.cell(row=7+a, column=4).value = str(message.Sender)
103
+     ws1.cell(row=7+a, column=4).value = str(message.Sender)
104
104
 
105
- ws1.cell(row=7+a, column=5).value = str(message.body[0:100])
105
+     ws1.cell(row=7+a, column=5).value = str(message.body[0:100])
106
106
 
107
- if message.Attachments.Count > 0:
107
+     if message.Attachments.Count > 0:
108
108
 
109
- myDate = RT.strftime('%Y/%m/%d %H:%M:%S')
109
+       myDate = RT.strftime('%Y/%m/%d %H:%M:%S')
110
110
 
111
- myDate = myDate.replace("/","-")
111
+       myDate = myDate.replace("/","-")
112
112
 
113
- myDate = myDate.replace(":","-")
113
+       myDate = myDate.replace(":","-")
114
114
 
115
- myDate = myDate.replace(" ","-")
115
+       myDate = myDate.replace(" ","-")
116
116
 
117
- datefolder_path = newfolder_path + "\" + myDate
117
+       datefolder_path = newfolder_path + "\" + myDate
118
118
 
119
- os.makedirs(datefolder_path)
119
+       os.makedirs(datefolder_path)
120
120
 
121
- for myAttachement in message.Attachments:
121
+       for myAttachement in message.Attachments:
122
122
 
123
- print(myAttachement.FileName)
123
+         print(myAttachement.FileName)
124
124
 
125
- myAttachement.SaveAsFile(datefolder_path + "\" +myAttachement.FileName)
125
+         myAttachement.SaveAsFile(datefolder_path + "\" +myAttachement.FileName)
126
126
 
127
- ws1.cell(row=7+a, column=6).value = "有"
127
+       ws1.cell(row=7+a, column=6).value = "有"
128
128
 
129
- else:
129
+     else:
130
130
 
131
- ws1.cell(row=7+a, column=6).value = "無"
131
+       ws1.cell(row=7+a, column=6).value = "無"
132
132
 
133
- a=a+1
133
+     a=a+1
134
134
 
135
135
 
136
136
 

2

修正②

2020/10/08 09:17

投稿

3939TJ55
3939TJ55

スコア109

test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,7 @@
88
88
 
89
89
  for message in messages:
90
90
 
91
- **RT = message.ReceivedTime**
91
+ RT = message.ReceivedTime
92
92
 
93
93
  hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
94
94
 

1

ご指摘通り変更致しました

2020/10/08 09:01

投稿

3939TJ55
3939TJ55

スコア109

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- ライブラリ
27
+ ```ライブラリ
28
28
 
29
29
  from openpyxl import load_workbook
30
30
 
@@ -141,3 +141,7 @@
141
141
  wb.save(newfilepath)
142
142
 
143
143
  print("保存しました")
144
+
145
+ コード
146
+
147
+ ```