Skip to content

Commit 3e12e6e

Browse files
authored
Merge pull request #7 from ws-garcia/added-support-for-empty-and-commented-lines
Added support for empty and commented lines
2 parents 08ee3ad + 92569b0 commit 3e12e6e

35 files changed

+595
-435
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
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 standard, but add some useful features like:
10+
* In-line comments (with a user-defined character).
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).
13+
14+
<a id="1">[1]</a>
15+
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.
16+
917
## Getting started
1018

1119
If you don't know how to get started with VBA-CSV Interface class, visit the [documentation repo](https://ws-garcia.github.io/VBA-CSV-interface/).

csv-data/CSVs.zip

159 KB
Binary file not shown.

docs/api/enumerations/escapetype.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ Provides a list of constants for use to configure the char used as escape one.
2727

2828
*variable* = `EscapeType`.*Constant*
2929

30-
---
31-
32-
## Remarks
33-
34-
The `EscapeType.NullChar` value is used with the`QuotationMode.All` setting to indicates the CSV file does not use any escape char in its whole length. This values combination conduces the CSV file to be parse/write assuming the `FieldsDelimiter` property is enough for the import/export operations.
35-
36-
In the case the `FieldsDelimiter` property is not enough for successfully done the import/export operations, the `QuotationMode.DoubleQuotes` value would be used for parse/write an CSV having fields to be escaped with double quote and the `QuotationMode.Apostrophe` values for parse/write an CSV having fields to be escaped with the apostrophe.
30+
>:pencil: **NOTE:**
31+
>
32+
>The `EscapeType.NullChar` value is used with the`QuotationMode.All` setting to indicates the CSV file does not use any escape char in its whole length. This values combination conduces the CSV 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 `EscapeType.DoubleQuotes` value would be used for parse/write an CSV having fields to be escaped with double quote and the `EscapeType.Apostrophe` values for parse/write an CSV having fields to be escaped with the apostrophe, using the `QuotationMode.Critical` mode.
3735
3836
See also
3937
: [EscapeChar Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapechar.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).

docs/api/enumerations/quotationmode.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ Provides a list of constants to configure the CSV parsing/writing operation beha
2626

2727
*variable* = `QuotationMode`.*Constant*
2828

29-
---
30-
31-
## Remarks
32-
33-
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.
29+
>:pencil: **NOTE:**
30+
>
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.
3432
3533
See also
3634
: [EscapeChar Property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/escapechar.html).

docs/api/methods/dumptoarray.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ The required *OutPutArray* argument is an identifier specifying a dynamic `Strin
2525

2626
_None_
2727

28-
---
29-
30-
## Remarks
31-
32-
**Note**: *Before dump data, is recommended to make a `ImportFromCSV` or `ImportFromCSVstring` method call.*
33-
34-
The *OutPutArray* parameter must be declared as dynamic `String` array. If user forget to do this, an error will occur.
28+
>:pencil: **NOTE:**
29+
>
30+
>Before dump data, is recommended to make a `ImportFromCSV` or `ImportFromCSVstring` method call. The *OutPutArray* parameter must be declared as dynamic `String` array. If user forget to do this, an error will occur.
3531
3632
See also
3733
: [ImportFromCSV method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/importfromcsv.html), [ImportFromCSVstring method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/importfromcsvstring.html).

docs/api/methods/dumptosheet.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Dumps the data from the current instance to an Excel WorkSheet.
1515

1616
## Syntax
1717

18-
*expression*.`DumpToSheet`*({WBookName}, {SheetName}, {RngName})*
18+
*expression*.`DumpToSheet`*({WBookName}, {SheetName}, {RngName:= "A1"})*
1919

2020
### Parameters
2121

@@ -46,11 +46,9 @@ Dumps the data from the current instance to an Excel WorkSheet.
4646

4747
_None_
4848

49-
---
50-
51-
## Remarks
52-
53-
**Note**: *Before dump data, is recommended to make a `ImportFromCSV` or `ImportFromCSVstring` method call.*
49+
>:pencil: **NOTE:**
50+
>
51+
>Before dump data, is recommended to make a `ImportFromCSV` or `ImportFromCSVstring` method call.
5452
5553
See also
5654
: [ImportFromCSV method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/importfromcsv.html), [ImportFromCSVstring method](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/importfromcsvstring.html).

docs/api/methods/exporttocsv.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ The required *csvArray* argument is an identifier specifying a `Variant` array v
2525

2626
_None_
2727

28-
---
29-
30-
## Remarks
31-
32-
**Note: Before invoke the `ExportToCSV` method, the user must to open a connection to the CSV file.**
33-
34-
The *csvArray* parameter must be declared as `Variant` array. Passing a variable that isn't an array will cause an error and the operation aborts.
28+
>:pencil: **NOTE:**
29+
>
30+
>Before invoke the `ExportToCSV` method, the user must to open a connection to the CSV file. The *csvArray* parameter must be declared as `Variant` array. Passing a variable that isn't an array will cause an error and the operation aborts.
3531
3632
See also
3733
: [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).

docs/api/methods/getdatafromcsv.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ The required *csvPathAndFilename* argument is an identifier specifying a `String
2525

2626
*Type*: `String`
2727

28-
---
29-
30-
## Remarks
31-
32-
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.
33-
34-
---
28+
>:pencil: **NOTE:**
29+
>
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.
3531
3632
## Behavior
3733

docs/api/methods/importfromcsv.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,50 @@ Imports a CSV file's content to an array.
1515

1616
## Syntax
1717

18-
*expression*.`ImportFromCSV`*({HeadersOmission})*
18+
*expression*.`ImportFromCSV`*({HeadersOmission:= `False`}, {PassControlToOS:= `True`})*
1919

2020
### Parameters
2121

22-
The optional *HeadersOmission* argument is an identifier specifying a `Boolean` variable.
22+
<table>
23+
<thead>
24+
<tr>
25+
<th style="text-align: left;">Part</th>
26+
<th style="text-align: left;">Description</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<tr>
31+
<td style="text-align: left;"><em>HeadersOmission</em></td>
32+
<td style="text-align: left;">Optional. Identifier specifying a <code>Boolean</code> variable.</td>
33+
</tr>
34+
<tr>
35+
<td style="text-align: left;"><em>PassControlToOS</em></td>
36+
<td style="text-align: left;">Optional. Identifier specifying a <code>Boolean</code> variable.</td>
37+
</tr>
38+
</tbody>
39+
</table>
2340

2441
### Return value
2542

2643
_None_
2744

28-
---
29-
30-
## Remarks
31-
32-
**Note: Before invoke the `ImportFromCSV` method, the user must to open a connection to the CSV file.**
33-
34-
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.
45+
>:pencil: **NOTE:**
46+
>
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.
48+
>
49+
>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.
3550
3651
See also
37-
: [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).
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).
3853

3954
---
4055

4156
## Behavior
4257

43-
The `FieldsDelimiter`, `RecordsDelimiter`, `EscapeChar`, `StartingRecord` and `EndingRecord` properties sets the method's behavior to the needs.
58+
User can set `CommentLineIndicator` 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.
59+
60+
>:warning: **CAUTION**
61+
>
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.
4463
4564
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

docs/api/methods/importfromcsvstring.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Parses a string and save its CSV data to an array.
1515

1616
## Syntax
1717

18-
*expression*.`ImportFromCSVstring`*(CSVstring, {HeadersOmission})*
18+
*expression*.`ImportFromCSVstring`*(CSVstring, {HeadersOmission:= `False`}, {PassControlToOS:= `False`})*
1919

2020
### Parameters
2121

@@ -35,26 +35,34 @@ Parses a string and save its CSV data to an array.
3535
<td style="text-align: left;"><em>HeadersOmission</em></td>
3636
<td style="text-align: left;">Optional. Identifier specifying a <code>Boolean</code> variable.</td>
3737
</tr>
38+
<tr>
39+
<td style="text-align: left;"><em>PassControlToOS</em></td>
40+
<td style="text-align: left;">Optional. Identifier specifying a <code>Boolean</code> variable.</td>
41+
</tr>
3842
</tbody>
3943
</table>
4044

4145
### Return value
4246

4347
_None_
4448

45-
---
46-
47-
## Remarks
48-
49-
If the *HeadersOmission* parameter is set to `True`, the *CSVstring* headers, first record, will be ignored by the parser only when the `StartingRecord` property is set to 1.
49+
>:pencil: **NOTE:**
50+
>
51+
>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.
52+
>
53+
>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.
5054
5155
See also
52-
: [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).
56+
: [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).
5357

5458
---
5559

5660
## Behavior
5761

58-
The `FieldsDelimiter`, `RecordsDelimiter`, `EscapeChar`, `StartingRecord` and `EndingRecord` properties sets the method's behavior to the needs.
62+
User can set `CommentLineIndicator` 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.
63+
64+
>:warning: **CAUTION**
65+
>
66+
>If the CSV file has no data, this is the file is an empty one, the `ImportFromCSVstring` method returns an empty array, that is, an array bounded from 0 to -1 and holding no elements and no data.
5967
60-
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)
68+
[Back to Methods overview](https://ws-garcia.github.io/VBA-CSV-interface/api/methods/)

0 commit comments

Comments
 (0)