-
Notifications
You must be signed in to change notification settings - Fork 0
/
furattoschedule..uws
169 lines (157 loc) · 5.02 KB
/
furattoschedule..uws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
CONST PATTERN_LIST_TIME = "[0-90-9]{1,2}:[0-90-9]{2}\s*(~|集合)"
CONST PATTERN_TIMETEXT = "[0-90-9]{1,2}時(半|[0-90-9]{1,2}分)?~[0-90-9]{1,2}時(半|[0-90-9]{1,2}分)?"
CONST PATTERN_PLACE_TIME = "集合[ ]*[::]([0-90-9]{1,2}時(半|[0-90-9]{1,2}分)?)?[ ]*([^ \r\n]+)"
CONST PATTERN_TIME = "(\d{1,2}):?(半|\d{1,2}分?)?"
CONST PATTERN_MAILADDR = "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*"
CONST PATTERN_TELEPHONE = "[0-90-9]{2,4}-[0-90-9]{2,4}-[0-90-9]{4}"
CONST PLACE_DEFAULT = "ふらっとステーション・とつか"
CONST LOG_SEPARATOR = "----------------------------------"
PUBLIC reg = CREATEOLEOBJ("VBScript.RegExp")
PUBLIC fso = CREATEOLEOBJ("Scripting.FileSystemObject")
PUBLIC m = NULL
COM_ERR_IGN
DIM word = GETACTIVEOLEOBJ( "Word.Application")
DIM files[0]
DIM doc_count = GETOLEITEM( word.documents )
COM_ERR_RET
IFB doc_count <= 0 OR COM_ERR_FLG THEN
MSGBOX("ふらっとステーション・とつか わくわくだより ファイルを開いてください")
EXIT
ENDIF
GETTIME()
RESIZE(files, doc_count)
FOR i = 0 TO doc_count - 1
files[i] = ALL_OLE_ITEM[i].name
NEXT
// ドキュメントファイルを選択
DIM file = SLCTBOX(SLCT_CMB + SLCT_STR, 0, "ファイルを選択", files)
IF file = "-1" THEN EXITEXIT
// ドキュメントファイルを開く
DIM doc = word.documents(file)
DIM fid = FOPEN(fso.buildPath(GET_CUR_DIR, "import.csv"), F_WRITE1)
DIM row = 1
FPUT(fid, "Start Date", row, 1)
FPUT(fid, "Start Time", row, 2)
FPUT(fid, "End Date", row, 3)
FPUT(fid, "End Time", row, 4)
FPUT(fid, "Subject", row, 5)
FPUT(fid, "Location", row, 6)
FPUT(fid, "Description", row, 7)
// テーブル走査
FOR i = 1 TO doc.tables.count
DIM table = doc.tables[i]
FOR l = 1 TO table.range.cells.count
DIM date
DIM text
DIM time
DIM r = table.range
DIM t = TRIM(r.cells[l].range.text)
SELECT r.cells[l].columnIndex
CASE 1
date = STRCONV(t, SC_HALFWIDTH)
CASE 3
text = t
CASE 4
time = SPLIT(t, "~")
SELEND
IF r.cells[l].columnIndex <> 4 THEN CONTINUE
// データ化
IF text = "" THEN CONTINUE
IF text = "定休日" THEN CONTINUE
m = regexecute("^([^□]*)(.*)", text)
event = m.item[0].subMatches[0]
text = m.item[0].subMatches[1]
PRINT event
PRINT LOG_SEPARATOR
DIM info = text
DIM sttime = ""
DIM edtime = ""
DIM detail = ""
DIM place = ""
sttime = normalizetime(time[0])
edtime = normalizetime(time[1])
IFB info = "" THEN
PRINT "詳細文が見つかりません"
detail = ""
place = PLACE_DEFAULT
ELSE
PRINT "詳細文が見つかりました"
detail = info
DIM pm = regexecute(PATTERN_PLACE_TIME, detail)
IFB pm.count > 0 THEN
place = TRIM(pm.item[0].subMatches[2])
IF STRCONV(place, SC_HALFWIDTH) = "ふらっとST" THEN place = PLACE_DEFAULT
ELSE
place = PLACE_DEFAULT
ENDIF
ENDIF
// 電話番号・メールアドレス削除
detail = regreplace(regreplace(detail, "", PATTERN_MAILADDR), "", PATTERN_TELEPHONE)
PRINT sttime + "~" + edtime
PRINT detail
PRINT place
PRINT ""
// 出力
DIM d = G_TIME_YY4 + "/" + (G_TIME_MM + 1) + "/" + date
row = row + 1
FPUT(fid, d, row, 1)
FPUT(fid, sttime, row, 2)
FPUT(fid, d, row, 3)
FPUT(fid, edtime, row, 4)
FPUT(fid, "<#DBL>" + event + "<#DBL>", row, 5)
FPUT(fid, "<#DBL>" + place + "<#DBL>", row, 6)
FPUT(fid, "<#DBL>" + detail + "<#DBL>", row, 7)
NEXT
NEXT
FCLOSE(fid)
MSGBOX("インポート用CSVファイルがスクリプトファイルのあるフォルダに作成されました。<#CR>Googleカレンダーのインポート機能よりインポートしてください")
///
/// スペース類文字を削除する
///
FUNCTION removespaces(text)
RESULT = regreplace(text, "", "[ \r\n]")
FEND
///
/// 文字列形式の時刻表記をGoogleカレンダーの時刻表記に変換
///
FUNCTION normalizetime(time)
DIM s = STRCONV(time, SC_HALFWIDTH)
DIM m = regexecute(PATTERN_TIME, s)
IFB m.count > 0 THEN
DIM h = m.item[0].subMatches[0]
DIM n = m.item[0].subMatches[1]
IF n = "半" THEN n = "30"
IF n = "" THEN n = "00"
PRINT h + ":" + n
RESULT = h + ":" + n
ELSE
RESULT = ""
ENDIF
FEND
///
/// 正規表現検索を実行する
///
FUNCTION regexecute(pattern, str, ignoreCase=true,global=true)
reg.IgnoreCase = ignoreCase
reg.Global = global
reg.Pattern = pattern
RESULT = reg.execute(str)
FEND
FUNCTION regtok(pattern, var str, ignoreCase=true,global=true)
DIM m = regexecute(pattern, str, ignoreCase, global)
IFB m.count > 1 THEN
DIM mm = m.item[0]
DIM f = mm.firstindex + mm.length
RESULT = COPY(str, 1, f)
str = COPY(str, f + 1)
ELSE
RESULT = str
str = ""
ENDIF
FEND
FUNCTION regreplace(str, replacement, pattern, ignoreCase=true,global=true)
reg.IgnoreCase = ignoreCase
reg.Global = global
reg.Pattern = pattern
RESULT = reg.replace(str, replacement)
FEND