-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatchSpreadsheetToXML.rbbas
168 lines (151 loc) · 3.86 KB
/
BatchSpreadsheetToXML.rbbas
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
#tag Class
Protected Class BatchSpreadsheetToXML
Inherits thread
#tag Event
Sub Run()
dim file_index, row_index as integer
dim f as folderitem
dim data as spreadsheet
dim t as string
dim d as dlgProgress
if dest = nil then
dest = SelectFolder()
if dest = nil then
return
end if
end if
if not dest.IsWriteable or not dest.directory or not dest.exists then
ReportError "Cannot write files to " + dest.name, false
return
end if
d = new dlgProgress
d.progress.Maximum = fileList.ubound + 1
d.maintask.caption = "Processing"
d.left = (caller.width - d.width) * 0.5 + caller.left
d.top = (caller.height - d.Height) * 0.5 + caller.top
d.Show
for file_index = 0 to fileList.ubound
f = fileList(file_index)
d.maintask.caption = "Processing " + f.name
d.progress.value = file_index
data = new spreadsheet( f, AutoEncoding(f, defaultEncoding) )
for row_index = 1 to data.rowcount - 1
d.Update.Caption = "Row " + str(row_index) + " of " + str( data.rowcount - 1 )
d.refresh
t = SpreadsheetAndTemplateToXML( data, template, row_index, errorList, dest, "Filename", output_filename_extension, true )
if not d.visible then
exit for
end if
next
if not d.visible then
exit for
end if
next
d.close
if Caller isA ThreadCaller then
ThreadCaller(Caller).ThreadDone
end if
End Sub
#tag EndEvent
#tag Method, Flags = &h0
Sub Constructor(theFileList() as folderItem, theTemplate as string, theDestination as FolderItem, theErrorList() as string, theDefaultEncoding as string, theCaller as Window, filename_extension as string = "xml")
fileList = theFileList
template = theTemplate
theDestination = theDestination
errorList = theErrorList
defaultEncoding = theDefaultEncoding
caller = theCaller
output_filename_extension = filename_extension
End Sub
#tag EndMethod
#tag Property, Flags = &h0
caller As Window
#tag EndProperty
#tag Property, Flags = &h0
defaultEncoding As string
#tag EndProperty
#tag Property, Flags = &h0
dest As FolderItem
#tag EndProperty
#tag Property, Flags = &h0
errorList() As string
#tag EndProperty
#tag Property, Flags = &h0
fileList() As folderitem
#tag EndProperty
#tag Property, Flags = &h0
output_filename_extension As String = "xml"
#tag EndProperty
#tag Property, Flags = &h0
template As string
#tag EndProperty
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
Type="Integer"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
Type="Integer"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="Priority"
Visible=true
Group="Behavior"
InitialValue="5"
Type="Integer"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="StackSize"
Visible=true
Group="Behavior"
InitialValue="0"
Type="Integer"
InheritedFrom="thread"
#tag EndViewProperty
#tag ViewProperty
Name="caller"
Group="Behavior"
InitialValue="0"
Type="Window"
#tag EndViewProperty
#tag ViewProperty
Name="defaultEncoding"
Group="Behavior"
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="template"
Group="Behavior"
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass