-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.vbs
135 lines (107 loc) · 3.27 KB
/
tool.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
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "[A-Z]{5}[0-9]{3}"
Set WshShell = CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strCurDir & "\out.csv", True)
Set allDate = CreateObject("System.Collections.ArrayList")
Set dataList = CreateObject("Scripting.Dictionary")
For Each fileName In objFSO.GetFolder(strCurDir).Files
If LCase(objFSO.GetExtensionName(fileName.Name)) = "xls" Then
Set objExcel = CreateObject("Excel.Application")
'fileName = "bien_ban_doi_soat_S18759785_Cong_ty_Co_phan_Duoc_pham_Pharmacity_1629705602_856.xls"
Set objWorkbook = objExcel.Workbooks.Open(fileName)
intRow = 27
ngay = objExcel.Cells(10, 5).Value
tienCod = objExcel.Cells(12, 8).Value
phiDV = objExcel.Cells(13, 8).Value
soDon = 0
allDate.add ngay
Do Until objExcel.Cells(intRow,1).Value = ""
row = objExcel.Cells(intRow, 8).Value
Set colMatches = objRegEx.Execute(row)
If colMatches.Count > 0 Then
For Each strCode in colMatches
add ngay, strCode
Next
Else
Wscript.Echo fileName & " not found code at line " & intRow
End If
intRow = intRow + 1
soDon = soDon + 1
Loop
Wscript.Echo "File: " & fileName
Wscript.Echo "Ngay: " & ngay
Wscript.Echo "Tien Cod: " & tienCod
Wscript.Echo "Phi DV: " & phiDV
Wscript.Echo "So don: " & soDon
Wscript.Echo "================================================================================"
addValue ngay, ".Tien Cod", tienCod
addValue ngay, ".PhiDV", phiDv
addValue ngay, ".So don", soDon
objExcel.Quit
end if
next
allDate.sort
rowWrite = "Ngay,"
For i = 0 To allDate.Count-1
rowWrite = rowWrite & allDate(i) & ","
next
objFile.Write rowWrite & vbCrLf
for each code in BubbleSort(dataList.keys)
Set data = dataList.Item(code)
rowWrite = code & ","
For i = 0 To allDate.Count-1
dateShow = allDate(i)
if data.exists(dateShow) then
rowWrite = rowWrite & data(dateShow) & ","
else
rowWrite = rowWrite & ","
end if
next
objFile.Write rowWrite & vbCrLf
next
objFile.Close
function add(date, codeRaw)
code = UCase(codeRaw)
if not dataList.Exists(code) then
set data = CreateObject("Scripting.Dictionary")
data.Add date, 1
dataList.add code, data
else
Set data = dataList.Item(code)
if not data.Exists(date) then
data.add date, 1
else
numberNow = data(date)
data.remove date
data.add date, (numberNow + 1)
end if
end if
end function
function addValue(date, codeRaw, value)
code = UCase(codeRaw)
if not dataList.Exists(code) then
set data = CreateObject("Scripting.Dictionary")
data.Add date, value
dataList.add code, data
else
Set data = dataList.Item(code)
if not data.Exists(date) then
data.add date, value
end if
end if
end function
Function BubbleSort(arrValues)
Dim j, k, Temp
For j = 0 To UBound(arrValues) - 1
For k = j + 1 To UBound(arrValues)
If strComp(arrValues(j),arrValues(k)) < 0 Then
Temp = arrValues(j)
arrValues(j) = arrValues(k)
arrValues(k) = Temp
End If
Next
Next
BubbleSort = arrValues
End Function