-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLibCsv.bas
52 lines (48 loc) · 1.97 KB
/
LibCsv.bas
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
Attribute VB_Name = "LibCsv"
'===============================================================================
' Модуль : LibCsv
' Версия : 2025.01.13
' Автор : elvin-nsk ([email protected])
' Сайт : https://github.com/elvin-nsk/LowCoupledFromCore
' Назначение : вспомогательные функции к классу CsvUtils
' : для парсинга csv-файлов
' Зависимости : CsvUtils, LibCore
'===============================================================================
Option Explicit
Public Function FileToKeyedColumns( _
ByVal CsvFile As String, _
Optional ByVal CharSet As String = "utf-8", _
Optional ByVal CsvSeparator As String = ";" _
) As Scripting.IDictionary
Set FileToKeyedColumns = _
TableToKeyedColumns( _
GetTableFromFile(CsvFile, CharSet, CsvSeparator) _
)
End Function
Public Function GetTableFromFile( _
ByVal CsvFile As String, _
Optional ByVal CharSet As String = "utf-8", _
Optional ByVal CsvSeparator As String = ";" _
) As String()
Dim Str As String
Str = ReadFileAD(CsvFile, CharSet)
GetTableFromFile = _
CsvUtils.New_(CsvSeparator) _
.ParseCsvToArray(Str, False)
End Function
Public Function TableToKeyedColumns( _
ByRef Table() As String _
) As Scripting.IDictionary
Dim Dic As New Scripting.Dictionary
Dim Row As Long
Dim Column As Long
Dim Key As String
For Column = 1 To UBound(Table, 2)
Key = Table(1, Column)
Dic.Add Key, New Collection
For Row = 2 To UBound(Table, 1)
Dic(Key).Add Table(Row, Column)
Next Row
Next Column
Set TableToKeyedColumns = Dic
End Function