-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprov.vbs
executable file
·185 lines (171 loc) · 5.04 KB
/
prov.vbs
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'
' Run as cscript //NoLogo prov.vbs [-p] [-d DELIMITER] -o OVERLAY.XLS [-i INPUT.CSV] -f FORMAT.TXT
'
'--------------------------------------------------
' 共通処理
'
Option Explicit
Function include(filename)
ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile(filename).ReadAll()
End Function
include("mytoolkit.vbs")
'--------------------------------------------------
' 大局変数
'
Dim objEndSw : Set objEndSw = new MySwitch
Dim objMisc : Set objMisc = new MyMisc
' User coding start
Dim objOpt : Set objOpt = new MyOption
Dim objStdio : Set objStdio = new MyStdio
Dim objOverlay : Set objOverlay = new MyExcel
Dim objInput : Set objInput = new MyFso
Dim objFormat : Set objFormat = new MyFso
Dim objPreviewSw : Set objPreviewSw = new MySwitch
Dim strDelimiter : strDelimiter = ","
Dim strOverlayFilename : strOverlayFilename = ""
Dim strInputFilename : strInputFilename = ""
Dim strFormatFilename : strFormatFilename = ""
Dim arrayFormatRec : arrayFormatRec = Array()
Dim strRec
' User coding end
'--------------------------------------------------
' 処理開始
'
sub_open ' オープン処理
sub_initialize ' 開始処理
While objEndSw.isOff
sub_main ' 主処理
Wend
sub_terminate ' 終了処理
sub_close ' クローズ処理
objMisc.exitProg(0)
'--------------------------------------------------
' オープン処理
'
Sub sub_open
' User coding start
objOpt.initialize("-h=n,--help=n,-p=n,-d=y,-o=y,-i=y,-f=y")
If objOpt.isSpecified("-h") or objOpt.isSpecified("--help") Then
objStdio.writeLine "Usage : cscript //NoLogo prov.vbs [-p] [-d DELIMITER] -o OVERLAY.XLS [-i INPUT.CSV] -f FORMAT.TXT"
objStdio.writeLine "Print formatted data with overlay."
objStdio.writeLine ""
objStdio.writeLine " -p preview mode."
objStdio.writeLine " -d DELIMITER use DELIMITER instead of comma for INPUT.CSV."
objStdio.writeLine " -o OVERLAY.XLS overlay definition by excel."
objStdio.writeLine " -i INPUT.CSV input data in csv format. If omitted then read stdin."
objStdio.writeLine " -f FORMAT.TXT format definition for INPUT.CSV."
objStdio.writeLine " each line should have like ""1=A1"""
objStdio.writeLine " ""1=A1"" means ""1st column"" in INPUT.CSV should be placed into ""A1"" cell in OVERLAY.XLS"
objEndSw.turnOn
End If
If objEndSw.isOff Then
If objOpt.isSpecified("-p") Then
objPreviewSw.turnOn
End If
If objOpt.isSpecified("-d") Then
strDelimiter = objOpt.getValue("-d")
End If
strOverlayFilename = objOpt.getValue("-o")
objOverlay.open(strOverlayFilename)
strInputFilename = objOpt.getValue("-i")
If strInputFilename <> "" Then
objInput.openInput(strInputFilename)
End If
strFormatFilename = objOpt.getValue("-f")
objFormat.openInput(strFormatFilename)
Redim arrayFormatRec(-1)
End If
' User coding end
End Sub
'--------------------------------------------------
' 開始処理
'
Sub sub_initialize
' User coding start
Dim i
Dim objStrFormatRec : Set objStrFormatRec = new MyString
If objEndSw.isOff Then
i = 0
objStrFormatRec.setValue objFormat.readLine
While objFormat.isReadSuccess
If objStrFormatRec.isMatch("^[0-9][0-9]*=[A-za-z][A-Za-z]*[0-9][0-9]*$") Then
Redim Preserve arrayFormatRec(i)
arrayFormatRec(i) = objStrFormatRec.getValue
i = i + 1
End If
objStrFormatRec.setValue objFormat.readLine
Wend
strRec = readRec
End If
Set objStrFormatRec = Nothing
' User coding end
End Sub
'--------------------------------------------------
' 主処理
'
Sub sub_main
' User coding start
Dim i
Dim arrayIndexCell
Dim objStr : Set objStr = new MyString
Dim objCsv : Set objCsv = new MyCsv
objCsv.setDelimiter strDelimiter
objCsv.setRec strRec
i = 0
While i <= Ubound(arrayFormatRec)
objStr.setValue arrayFormatRec(i)
arrayIndexCell = Split(arrayFormatRec(i), "=")
objOverlay.setCell 1, arrayIndexCell(1), objCsv.getValueByIndex(CInt(arrayIndexCell(0))-1)
i = i + 1
Wend
If objPreviewSw.isOn Then
objOverlay.preview 1
Else
objOverlay.print 1
End If
Set objStr = Nothing
Set objCsv = Nothing
strRec = readRec
' User coding end
End Sub
'--------------------------------------------------
' 終了処理
'
Sub sub_terminate
' User coding start
' User coding end
End Sub
'--------------------------------------------------
' クローズ処理
'
Sub sub_close
' User coding start
If objOpt.isSpecified("-h") or objOpt.isSpecified("--help") Then
' Do nothing
Else
objOverlay.close
If strInputFilename <> "" Then
objInput.close
End If
objFormat.close
End If
' User coding end
End Sub
'--------------------------------------------------
' その他の処理
'
' User coding start
Function readRec
If strInputFilename = "" Then
readRec = objStdio.readLine
If objStdio.isReadFailure Then
objEndSw.turnOn
End If
Else
readRec = objInput.readLine
If objInput.isReadFailure Then
objEndSw.turnOn
End If
End If
End Function
' User coding end