Skip to content

Commit 6a25d6b

Browse files
authored
Merge pull request #15 from ws-garcia/TSV-files-support
TSV files support
2 parents e28f528 + ac41eb1 commit 6a25d6b

28 files changed

+313
-238
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
VBA CSV interface is a class module developed to accomplish the data exchange task between VBA arrays and CSV files at high speed. Projects from [@sdkn104](https://github.com/sdkn104/VBA-CSV) and [@Senipah](https://github.com/Senipah/VBA-Better-Array), both on Github, were used for comparative performance purposes.
88

9-
The parser is compatible with those CSV files compliant with the RFC-4180 specs, but add some useful features like:
10-
* In-line comments (with a user-defined character). See [Papa Parse](https://www.papaparse.com/) project.
11-
* Skip blanks lines and empty ones.
12-
* User-defined escape character (option not available in _Power Query for Excel 2019_ and with some inconsistences when use the _From Text(Legacy)_ wizard)[[1]](#1).
9+
## Advantages
10+
* Writes and reads files at high speed.
11+
* Supports those CSV's that follows the RFC-4180 specs.
12+
* Supports [Tab Separated Values(TSV)](https://www.iana.org/assignments/media-types/text/tab-separated-values) files. Gracefully handles line-breaks inside TSV fields enclosed in double-quotes.
13+
* Auto exclude any quote mark when data is imported.
14+
* Allows an user-defined escape token (option not available in _Power Query for Excel 2019_ and with some inconsistences when user launch the _From Text(Legacy)_ wizard)[[1]](#1).
15+
* Supports One-dimensional arrays, Two-dimensional arrays and [jagged arrays](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/jagged-arrays).
16+
* User has the option to import only certain range of records from given file.
17+
* Supports in-line comments (with a user-defined character). See [Papa Parse](https://www.papaparse.com/) project.
18+
* Supports blanks lines and empty ones.
1319

1420
<a id="1">[1]</a>
1521
Power Query, and its legacy counterpart, was not able to handle fields’ embedded line breaks when the CSV's "Text qualifier" is a Single Quote or the Apostrophe char.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: EscapeTokens
3+
parent: Enumerations
4+
grand_parent: API
5+
nav_order: 1
6+
---
7+
8+
# EscapeTokens Enum
9+
{: .fs-9 }
10+
11+
Provides a list of constants for use to configure the char used as escape one.
12+
{: .fs-6 .fw-300 }
13+
14+
---
15+
16+
## Parts
17+
18+
|**_Constant_**|**_Member name_**|
19+
|:----------|:----------|
20+
|0|*NullChar*|
21+
|1|*Apostrophe*|
22+
|2|*DoubleQuotes*|
23+
24+
---
25+
26+
## Syntax
27+
28+
*variable* = `EscapeTokens`.*Constant*
29+
30+
>📝**Note**
31+
>{: .text-grey-lt-000 .bg-green-000 }
32+
>The `EscapeTokens.NullChar` value is used with the`QuotationMode.All` setting to indicates the CSV/TSV file does not use any escape char in its whole length. This values combination conduces the file to be parse/write assuming the `FieldsDelimiter` property is enough for the import/export operations.
33+
>
34+
>In the case the `FieldsDelimiter` property is not enough for successfully done the import/export operations, the `EscapeTokens.DoubleQuotes` value would be used for parse/write an CSV/TSV having fields to be escaped with double quote and the `EscapeTokens.Apostrophe` values for parse/write a file having fields to be escaped with the apostrophe, using the `QuotationMode.Critical` mode.
35+
{: .text-grey-dk-300 .bg-grey-lt-000 }
36+
37+
See also
38+
: [EscapeToken Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapetoken.html), [QuotationMode Enumeration](https://ws-garcia.github.io/VBA-CSV-interface/api/enumerations/quotationmode.html), [FieldsDelimiter Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/fieldsdelimiter.html).
39+
40+
[Back to Enumerations overview](https://ws-garcia.github.io/VBA-CSV-interface/api/enumerations/)

docs/api/enumerations/escapetype.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/api/enumerations/quotationmode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nav_order: 2
88
# QuotationMode Enum
99
{: .fs-9 }
1010

11-
Provides a list of constants to configure the CSV parsing/writing operation behavior.
11+
Provides a list of constants to configure the CSV/TSV parsing/writing operation behavior.
1212
{: .fs-6 .fw-300 }
1313

1414
---
@@ -28,10 +28,10 @@ Provides a list of constants to configure the CSV parsing/writing operation beha
2828

2929
>📝**Note**
3030
>{: .text-grey-lt-000 .bg-green-000 }
31-
>The `QuotationMode.Critical` value, default one, is used to indicates the CSV file must use escape char only in fields having special char. The `QuotationMode.All` value most be used for those CSV files in wich all its fields will be escaped with the escape char given with the `EscapeChar` property.
31+
>The `QuotationMode.Critical` value, default one, is used to indicates the file must use escape char only in fields having special char. The `QuotationMode.All` value most be used for those files in wich all its fields will be escaped with the escape char given with the `EscapeToken` property.
3232
{: .text-grey-dk-300 .bg-grey-lt-000 }
3333

3434
See also
35-
: [EscapeChar Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapechar.html).
35+
: [EscapeToken Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapetoken.html).
3636

3737
[Back to Enumerations overview](https://ws-garcia.github.io/VBA-CSV-interface/api/enumerations/)

docs/api/methods/dumptoarray.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ See also
3939

4040
The `DumpToArray` method makes a copy of all the data stored in the current instance. The data is returned in the *OutPutArray* parameter for avoid additional data copies in the internals.
4141

42-
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV data any more. In the same way, the `DumpToArray` method doesn’t perform any modifications to the *OutPutArray* array for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
42+
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV/TSV data any more. In the same way, the `DumpToArray` method doesn’t perform any modifications to the *OutPutArray* array for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
4343

4444
>⚠️**Caution**
4545
>{: .text-grey-lt-000 .bg-green-000 }
46-
>The data is always returned in a Two-dimensional array, even when the imported CSV file only contain a field per record.
46+
>The data is always returned in a Two-dimensional array, even when the imported file only contain a field per record.
4747
{: .text-grey-dk-300 .bg-yellow-000 }
4848

4949
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

docs/api/methods/dumptojaggedarray.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ See also
4242

4343
The `DumpToJaggedArray` method makes a copy of all the data stored in the current instance. The data is returned in the *OutPutArray* parameter for avoid additional data copies in the internals.
4444

45-
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV data any more. In the same way, the `DumpToJaggedArray` method doesn’t perform any modifications to the *OutPutArray* array for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
45+
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV/TSV data any more. In the same way, the `DumpToJaggedArray` method doesn’t perform any modifications to the *OutPutArray* array for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
4646

4747
>📝**Note**
4848
>{: .text-grey-lt-000 .bg-green-000 }

docs/api/methods/dumptosheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ See also
6060

6161
When the *WBookName* parameter is omitted the data is dumped into the Workbook that holds the CSV interface's *VBAProject*. Omitting the *SheetName* parameter adds a new Worksheet to the desired Workbook. Also, if the *RngName* parameter is omitted the data will dumped starting on the "A1" named cell in the desired Worksheet.
6262

63-
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV data any more. In the same way, the `DumpToSheet` method doesn’t perform any action for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
63+
The dumped data will be successively erased from memory, in other words, the current instance will doesn't hold the read CSV/TSV data any more. In the same way, the `DumpToSheet` method doesn’t perform any action for subsequent calls not preceded by one `ImportFromCSV` or `ImportFromCSVstring` method call.
6464
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

docs/api/methods/exporttocsv.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nav_order: 5
88
# ExportToCSV
99
{: .fs-9 }
1010

11-
Exports an array's content to a CSV file.
11+
Exports an array's content to a CSV/TSV file.
1212
{: .fs-6 .fw-300 }
1313

1414
---
@@ -44,16 +44,16 @@ _None_
4444

4545
>📝**Note**
4646
>{: .text-grey-lt-000 .bg-green-000 }
47-
>Before invoke the `ExportToCSV` method, the user must to open a connection to the CSV file. Passing a variable that isn't an array will cause an error and the operation aborts.
47+
>Before invoke the `ExportToCSV` method, the user must to open a connection to the file. Passing a variable that isn't an array will cause an error and the operation aborts.
4848
{: .text-grey-dk-300 .bg-grey-lt-000 }
4949

5050
See also
51-
: [OpenConnection method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/openconnection.html), [FieldsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/fieldsdelimiter.html), [RecordsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/recordsdelimiter.html), [EscapeChar property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapechar.html).
51+
: [OpenConnection method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/openconnection.html), [FieldsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/fieldsdelimiter.html), [RecordsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/recordsdelimiter.html), [EscapeToken property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapetoken.html).
5252

5353
---
5454

5555
## Behavior
5656

57-
The `FieldsDelimiter`, `RecordsDelimiter` and `EscapeChar` properties sets the method's behavior to the needs.
57+
The `FieldsDelimiter`, `RecordsDelimiter` and `EscapeToken` properties sets the method's behavior to the needs.
5858

5959
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

docs/api/methods/getdatafromcsv.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nav_order: 6
88
# GetDataFromCSV
99
{: .fs-9 }
1010

11-
Dumps a CSV file content to a string variable
11+
Dumps a CSV/TSV file content to a string variable
1212
{: .fs-6 .fw-300 }
1313

1414
---
@@ -27,7 +27,7 @@ The required *csvPathAndFilename* argument is an identifier specifying a `String
2727

2828
>📝**Note**
2929
>{: .text-grey-lt-000 .bg-green-000 }
30-
>The *csvPathAndFilename* parameter must be the full path to the target CSV file, this means, the parameter holds the folder path, the file name and the ".csv" extension.
30+
>The *csvPathAndFilename* parameter must be the full path to the target file, this means, the parameter holds the folder path, the file name and the extension.
3131
{: .text-grey-dk-300 .bg-grey-lt-000 }
3232

3333
## Behavior

docs/api/methods/importfromcsv.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nav_order: 7
88
# ImportFromCSV
99
{: .fs-9 }
1010

11-
Imports a CSV file's content to the current instance.
11+
Imports a CSV/TSV file's content to the current instance.
1212
{: .fs-6 .fw-300 }
1313

1414
---
@@ -44,22 +44,22 @@ _None_
4444

4545
>📝**Note**
4646
>{: .text-grey-lt-000 .bg-green-000 }
47-
>If the *HeadersOmission* parameter is set to `True`, the CSV file headers, first record, will be ignored by the parser only when the `StartingRecord` property is set to 1.
47+
>If the *HeadersOmission* parameter is set to `True`, the file headers, first record, will be ignored by the parser only when the `StartingRecord` property is set to 1.
4848
>The *PassControlToOS* parameter allows user to pass control to the operating system. Control is returned after the operating system has finished processing the events in its queue.
4949
{: .text-grey-dk-300 .bg-grey-lt-000 }
5050

5151
See also
52-
: [OpenConnection method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/openconnection.html), [FieldsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/fieldsdelimiter.html), [RecordsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/recordsdelimiter.html), [EscapeChar property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapechar.html), [StartingRecord property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/startingrecord.html), [EndingRecord property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/endingrecord.html), [CommentLineIndicator property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/commentlineindicator.html).
52+
: [OpenConnection method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/openconnection.html), [FieldsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/fieldsdelimiter.html), [RecordsDelimiter property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/recordsdelimiter.html), [EscapeToken property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapetoken.html), [StartingRecord property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/startingrecord.html), [EndingRecord property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/endingrecord.html), [CommentsToken property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/commentstoken.html).
5353

5454
---
5555

5656
## Behavior
5757

58-
User can set `CommentLineIndicator` property for those CSV files having a combination of empties lines, blanks lines or commented ones for parse the file ONLY when the parser is working on `QuotationMode.Critical` mode. In that mode, the cited lines are simply skipped, leaving no empty values between records separated by this kind of lines. In other words, if the CSV file holds a record and then some special lines (blank, empty or commented) and then another record, the second record will be saved contiguous to the first record ignoring the lines between both.
58+
User can set `CommentsToken` property for those files having a combination of empties lines, blanks lines or commented ones for parse the file ONLY when the parser is working on `QuotationMode.Critical` mode. In that mode, the cited lines are simply skipped, leaving no empty values between records separated by this kind of lines. In other words, if the file holds a record and then some special lines (blank, empty or commented) and then another record, the second record will be saved contiguous to the first record ignoring the lines between both.
5959

6060
>⚠️**Caution**
6161
>{: .text-grey-lt-000 .bg-green-000 }
62-
>Before invoke the `ImportFromCSV` method, the user must to open a connection to the CSV file. If the CSV file has no data, this is the file is an empty one, the `ImportFromCSV` method returns an empty array, that is, an array bounded from 0 to -1 and holding no elements and no data.
62+
>Before invoke the `ImportFromCSV` method, the user must to open a connection to the file. If the target file has no data (the file is an empty one) the `ImportFromCSV` method returns an empty array, that is, an array bounded from 0 to -1 and holding no elements and no data.
6363
{: .text-grey-dk-300 .bg-yellow-000 }
6464

6565
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

0 commit comments

Comments
 (0)