質問するログイン新規登録

質問編集履歴

4

修正

2020/10/08 09:31

投稿

3939TJ55
3939TJ55

スコア109

title CHANGED
File without changes
body CHANGED
@@ -18,7 +18,7 @@
18
18
  import os
19
19
 
20
20
  所定フォルダ内の「Book.xlsm」を指定して読み込む
21
- filepath = 'C:/Users/'
21
+ filepath = 'C:/Users/Desktop/python lesson/メール保存/Outlook_Book2.xlsx'
22
22
  wb = load_workbook(filename=filepath)
23
23
  ws1 = wb["データ"]
24
24
 
@@ -37,7 +37,7 @@
37
37
  foldermake = foldermake.replace("/","-")
38
38
  foldermake = foldermake.replace(":","-")
39
39
  foldermake = foldermake.replace(" ","-")
40
- newfolder_path = 'C:/Users/'+foldermake
40
+ newfolder_path = 'C:/Users/Desktop/python lesson/メール保存/Outlook_'+foldermake
41
41
  os.makedirs(newfolder_path)
42
42
 
43
43
  outlookの情報を取得
@@ -67,7 +67,7 @@
67
67
      a=a+1
68
68
 
69
69
  Outlook_Book2.xlsx」として所定のフォルダに保存
70
- newfilepath = 'C:/Users/'
70
+ newfilepath = ''C:/Users/Desktop/python lesson/メール保存/Outlook_Book2.xlsx'
71
71
  wb.save(newfilepath)
72
72
  print("保存しました")
73
73
  コード

3

インデント修正

2020/10/08 09:31

投稿

3939TJ55
3939TJ55

スコア109

title CHANGED
File without changes
body CHANGED
@@ -43,28 +43,28 @@
43
43
  outlookの情報を取得
44
44
  a=0
45
45
  for message in messages:
46
- RT = message.ReceivedTime
46
+   RT = message.ReceivedTime
47
- hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
47
+   hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
48
- if startdate <= hiduketime <= enddate:
48
+   if startdate <= hiduketime <= enddate:
49
- ws1.cell(row=7+a, column=1).value = a+1
49
+     ws1.cell(row=7+a, column=1).value = a+1
50
- ws1.cell(row=7+a, column=2).value = str(message.Subject)
50
+     ws1.cell(row=7+a, column=2).value = str(message.Subject)
51
- ws1.cell(row=7+a, column=3).value = hiduketime
51
+     ws1.cell(row=7+a, column=3).value = hiduketime
52
- ws1.cell(row=7+a, column=4).value = str(message.Sender)
52
+     ws1.cell(row=7+a, column=4).value = str(message.Sender)
53
- ws1.cell(row=7+a, column=5).value = str(message.body[0:100])
53
+     ws1.cell(row=7+a, column=5).value = str(message.body[0:100])
54
- if message.Attachments.Count > 0:
54
+     if message.Attachments.Count > 0:
55
- myDate = RT.strftime('%Y/%m/%d %H:%M:%S')
55
+       myDate = RT.strftime('%Y/%m/%d %H:%M:%S')
56
- myDate = myDate.replace("/","-")
56
+       myDate = myDate.replace("/","-")
57
- myDate = myDate.replace(":","-")
57
+       myDate = myDate.replace(":","-")
58
- myDate = myDate.replace(" ","-")
58
+       myDate = myDate.replace(" ","-")
59
- datefolder_path = newfolder_path + "\" + myDate
59
+       datefolder_path = newfolder_path + "\" + myDate
60
- os.makedirs(datefolder_path)
60
+       os.makedirs(datefolder_path)
61
- for myAttachement in message.Attachments:
61
+       for myAttachement in message.Attachments:
62
- print(myAttachement.FileName)
62
+         print(myAttachement.FileName)
63
- myAttachement.SaveAsFile(datefolder_path + "\" +myAttachement.FileName)
63
+         myAttachement.SaveAsFile(datefolder_path + "\" +myAttachement.FileName)
64
- ws1.cell(row=7+a, column=6).value = "有"
64
+       ws1.cell(row=7+a, column=6).value = "有"
65
- else:
65
+     else:
66
- ws1.cell(row=7+a, column=6).value = "無"
66
+       ws1.cell(row=7+a, column=6).value = "無"
67
- a=a+1
67
+     a=a+1
68
68
 
69
69
  Outlook_Book2.xlsx」として所定のフォルダに保存
70
70
  newfilepath = 'C:/Users/'

2

修正②

2020/10/08 09:17

投稿

3939TJ55
3939TJ55

スコア109

title CHANGED
File without changes
body CHANGED
@@ -43,7 +43,7 @@
43
43
  outlookの情報を取得
44
44
  a=0
45
45
  for message in messages:
46
- **RT = message.ReceivedTime**
46
+ RT = message.ReceivedTime
47
47
  hiduketime = datetime.datetime(RT.year, RT.month, RT.day, RT.hour, RT.minute, RT.second)
48
48
  if startdate <= hiduketime <= enddate:
49
49
  ws1.cell(row=7+a, column=1).value = a+1

1

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

2020/10/08 09:01

投稿

3939TJ55
3939TJ55

スコア109

title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,7 @@
11
11
  python 3.8.3
12
12
  VSCODE 
13
13
 
14
- ライブラリ
14
+ ```ライブラリ
15
15
  from openpyxl import load_workbook
16
16
  import win32com.client
17
17
  import datetime
@@ -69,4 +69,6 @@
69
69
  Outlook_Book2.xlsx」として所定のフォルダに保存
70
70
  newfilepath = 'C:/Users/'
71
71
  wb.save(newfilepath)
72
- print("保存しました")
72
+ print("保存しました")
73
+ コード
74
+ ```