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
|
Option Explicit
Const version = "1.1"
'This is the script-version of csvtolatex version 1.1
'So you can also use csvtolatex with a configuration file with the extension .ctl
'for more information see the docimentation
'Every one who uses this script agrees with the License you find in License.txt.
'here you write the path and the filename of the input-file you are using.
Const iPath = "C:\users\documents\inpufile.csv"
'here you write the path, where all output-files should be written
Const ePfad = "C:\users\documents\tables\"
'here you can switch between text- and mathmode
'for mathmode it is "$" for textmode it is "":
Const mode = "$"
'this is mathmode
'information for inputfile.csv
'every table begins with '/begin{' this defines the outputfile.
'example: /begin{output1.csv}
'every row in a table has to end with '//' respectivly ';//'
'if you are using program like MS Excel just write at the end of every row '//'
'every table ends with '/end'
'example: /end
'you may use '\cline' or '/cline' to make a \cline
'you may use '/blank', if a cell has to blank, but
'you can use '/.,' to have a semicolon (';') in your table
'now there is no need to change anything
Dim index, delete, lineend, zusatztext
Dim mnumber, worktext, testnumber, zwischen, addition, arbeitstext, geteilt, nCount, indexi, muellzahl, head
index = "0"
delete = "@€€@µ"
Dim Fso, iFile, eFile, Text, ePath
Set Fso = CreateObject("Scripting.FileSystemObject")
Set iFile = Fso.OpenTextFile(iPath)
Do Until iFile.AtEndOfStream
Text = iFile.ReadLine
Do While ((InStr(Text, ";//;")))
Text = Replace(Text, ";//;", ";//")
Loop
Text = Replace(Text, ";/endhead", ";// /endhead")
Do While ((InStr(Text, "/endhead;")))
Text = Replace(Text, "/endhead;", "/endhead")
Loop
If (InStr(Text, ";//")) Then
Dim muell
Text = Replace(Text, ";//", "")
arbeitstext = ""
geteilt = Split(Text, ";")
indexi = "0"
nCount = UBound(geteilt, 1) - LBound(geteilt, 1) + 1
muellzahl = "0"
zusatztext = mode
Do
zwischen = 1
'muell = MsgBox(Text & " >" & geteilt(indexi) & "< " & (Len(geteilt(indexi)) = 0), 0)
If InStr(geteilt(indexi), "/multicolumn{") Then
mnumber = InStr(geteilt(indexi), "/multicolumn{")
testnumber = InStr(geteilt(indexi), "}")
addition = "0"
zwischen = geteilt(indexi)
testnumber = testnumber - 1
zwischen = Left(zwischen, testnumber)
testnumber = InstrRev(zwischen, "{")
testnumber = Len(zwischen) - testnumber
zwischen = Right(zwischen, testnumber)
geteilt(indexi) = Replace(geteilt(indexi), "/multicolumn{", "\multicolumn{")
zusatztext = ""
ElseIf InStr(geteilt(indexi), "/multirow{") Then
geteilt(indexi) = Replace(geteilt(indexi), "/multirow{", " \multirow{")
zusatztext = ""
ElseIf ((Len(geteilt(indexi)) = 0) Or InStr(Text, "/cline{") Or InStr(Text, "\cline{")) Then
zusatztext = ""
Else
zusatztext = mode
End If
testnumber = indexi + 1
If InStr(testnumber, nCount) Then
arbeitstext = arbeitstext & zusatztext & geteilt(indexi) & zusatztext
Else
testnumber = indexi + zwischen
If (InStr(testnumber, nCount) And InStr(geteilt(indexi), "\multicolumn{")) Then
arbeitstext = arbeitstext & zusatztext & geteilt(indexi) & zusatztext
Else
arbeitstext = arbeitstext & zusatztext & geteilt(indexi) & zusatztext & "&"
End If
End If
indexi = indexi + zwischen
Loop Until (InStr(indexi, nCount))
Text = arbeitstext
head = " "
If InStr(Text, "/endhead") Then
Text = Replace(Text, "/endhead", "")
head = " \endhead "
End If
lineend = "\hline"
If InStr(Text, "/cline{") Then
Text = Replace(Text, "/cline{", "\cline{")
End If
If InStr(Text, "\cline{") Then
mnumber = InStr(Text, "\cline{") - 1
arbeitstext = Left(Text, mnumber)
zwischen = Replace(Text, arbeitstext, "")
lineend = zwischen
Text = arbeitstext
End If
Text = Replace(Text, "/.,", ";")
Text = Text & "\\ " & lineend & head
Text = Replace(Text, "&" & mode & "/blank", "&")
Text = Replace(Text, "&" & "/blank", "&")
eFile.WriteLine Text
End If
If InStr(Text, "/begin{") Then
Text = Replace(Text, "/begin{", "")
Text = Replace(Text, ";", "")
ePath = ePfad & Replace(Text, "}", "")
Set eFile = Fso.CreateTextFile(ePath)
End If
If InStr(Text, "/end") Then
eFile.Close
End If
Loop
iFile.Close
Text = MsgBox("Conversion complete!", 0, "csvtolatex " + version)
|