Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SheetAppender - change headers logic so that you can control to not append headers. #45

Closed
wants to merge 3 commits into from

Conversation

drgrieve
Copy link
Contributor

A have a sheet for which I want to every day append a csv file to it.

On the first day I want to include the headers (rows = 0) after that I do not.

Currently whatever value you pass to includeHeaders, it will always include the header as it will either add the header via csv.HeaderRecord or read all the rows (including headerrow).

I've changed the behaviour so that when you pass includeHeader = false, the first row is essentially skipped.

I believe this is a bug of the current build, but my change could also be a breaking change.

I only have one sheet/csv that I've tested on, but the change is working for this.

@SteveWinward
Copy link
Owner

@drgrieve Thank you for identifying this bug!

To try and minimize the impact to existing users of the SheetAppender class, I took a slightly different approach from your original pull request. I renamed the original parameter name includeHeaders to csvHasHeaderRecord to be more descriptive that this only tells you if the source CSV file has a header record as the first row in the CSV file.

I added a new optional parameter called skipWritingHeaderRow which lets you now configure if you want to avoid writing the header row into the actual Google spreadsheet file. I believe this now gives you the control you are looking for.

Here's an example below,

// write the CSV file for the first time to the Google Spreadsheet
var appender = new SheetAppender(sheetHelper);

appender.AppendCsv(filePath, csvHasHeaderRecord: true, skipWritingHeaderRow: false);
// append the CSV file, but don't write the header row to the Google Spreadsheet this time
var appender = new SheetAppender(sheetHelper);

appender.AppendCsv(filePath, csvHasHeaderRecord: true, skipWritingHeaderRow: true);

I pushed this update into the newest version on Nuget. If you download package version 2.0.19 you will get these changes.

https://github.com/SteveWinward/GoogleSheetsWrapper/releases/tag/v2.0.19

@drgrieve
Copy link
Contributor Author

@SteveWinward I tested the new release and this is working.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants