Skip to content

Commit 126919e

Browse files
committed
SheetAppender header row bug fix #45
1 parent 3545618 commit 126919e

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/GoogleSheetsWrapper/GoogleSheetsWrapper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageProjectUrl>https://github.com/SteveWinward/GoogleSheetsWrapper</PackageProjectUrl>
99
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1010
<RepositoryUrl>https://github.com/SteveWinward/GoogleSheetsWrapper</RepositoryUrl>
11-
<Version>2.0.18</Version>
11+
<Version>2.0.19</Version>
1212
<PackageTags>Google Sheets</PackageTags>
1313
<PackageReadmeFile>README.md</PackageReadmeFile>
1414
<Description>A simple wrapper library that makes it easier to perform CRUD operations against Google Sheets spreadsheets.</Description>

src/GoogleSheetsWrapper/SheetAppender.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,51 @@ public SheetAppender(SheetHelper sheetHelper)
4343
public void Init(string jsonCredentials)
4444
{
4545
_sheetHelper.Init(jsonCredentials);
46-
}
47-
46+
}
47+
4848
/// <summary>
4949
/// Appends a CSV file and all its rows into the current Google Sheets tab
5050
/// </summary>
5151
/// <param name="filePath"></param>
52-
/// <param name="includeHeaders"></param>
53-
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
52+
/// <param name="csvHasHeaderRecord">This boolean indicates whether the CSV file has a header record row or not</param>
53+
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
5454
/// <param name="batchSize">Increasing batch size may improve throughput. Default is conservative.</param>
55-
public void AppendCsv(string filePath, bool includeHeaders, int batchWaitTime = 1000, int batchSize = 100)
55+
/// <param name="skipWritingHeaderRow">This boolean indicates if you want to actually write the header row to the Google sheet</param>
56+
public void AppendCsv(string filePath, bool csvHasHeaderRecord, int batchWaitTime = 1000, int batchSize = 100, bool skipWritingHeaderRow = false)
5657
{
5758
using (var stream = new FileStream(filePath, FileMode.Open))
5859
{
59-
AppendCsv(stream, includeHeaders, batchWaitTime, batchSize);
60+
AppendCsv(stream, csvHasHeaderRecord, batchWaitTime, batchSize, skipWritingHeaderRow);
6061
}
6162
}
6263

6364
/// <summary>
6465
/// Appends a CSV file and all its rows into the current Google Sheets tab
6566
/// </summary>
6667
/// <param name="stream"></param>
67-
/// <param name="includeHeaders"></param>
68-
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
68+
/// <param name="csvHasHeaderRecord">This boolean indicates whether the CSV file has a header record row or not</param>
69+
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
6970
/// <param name="batchSize">Increasing batch size may improve throughput. Default is conservative.</param>
70-
public void AppendCsv(Stream stream, bool includeHeaders, int batchWaitTime = 1000, int batchSize = 100)
71+
/// <param name="skipWritingHeaderRow">This boolean indicates if you want to actually write the header row to the Google sheet</param>
72+
public void AppendCsv(Stream stream, bool csvHasHeaderRecord, int batchWaitTime = 1000, int batchSize = 100, bool skipWritingHeaderRow = false)
7173
{
7274
var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
7375
{
74-
HasHeaderRecord = includeHeaders
76+
HasHeaderRecord = csvHasHeaderRecord
7577
};
7678

77-
AppendCsv(stream, csvConfig, batchWaitTime, batchSize);
79+
AppendCsv(stream, csvConfig, batchWaitTime, batchSize, skipWritingHeaderRow);
7880
}
7981

8082
/// <summary>
8183
/// Appends a CSV file and all its rows into the current Google Sheets tab
8284
/// </summary>
8385
/// <param name="stream"></param>
8486
/// <param name="csvConfig"></param>
85-
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
87+
/// <param name="batchWaitTime">See https://developers.google.com/sheets/api/limits at last check is 60 requests a minute, so 1 second delay per request should avoid limiting</param>
8688
/// <param name="batchSize">Increasing batch size may improve throughput. Default is conservative.</param>
87-
public void AppendCsv(Stream stream, CsvConfiguration csvConfig, int batchWaitTime = 1000, int batchSize = 100)
89+
/// <param name="skipWritingHeaderRow">This boolean indicates if you want to actually write the header row to the Google sheet</param>
90+
public void AppendCsv(Stream stream, CsvConfiguration csvConfig, int batchWaitTime = 1000, int batchSize = 100, bool skipWritingHeaderRow = false)
8891
{
8992
using var streamReader = new StreamReader(stream);
9093
using var csv = new CsvReader(streamReader, csvConfig);
@@ -100,7 +103,8 @@ public void AppendCsv(Stream stream, CsvConfiguration csvConfig, int batchWaitTi
100103

101104
var currentBatchCount = 0;
102105

103-
if (csvConfig.HasHeaderRecord)
106+
// Only write the header record if its specified to not skip writing the header row
107+
if (csvConfig.HasHeaderRecord && !skipWritingHeaderRow)
104108
{
105109
currentBatchCount++;
106110

0 commit comments

Comments
 (0)