SteveWinward / GoogleSheetsWrapper

Google Sheets API .NET Wrapper Library
MIT License
48 stars 13 forks source link

A few questions #21

Closed ghost closed 1 year ago

ghost commented 1 year ago

The first one, where's the doc for the library? I was grinding the entire git in order to avoid opening an "issue" but couldn't find, so it leaves me with no choice but ask instead.

SteveWinward commented 1 year ago

@dahanj95,

With regards to the SheefFieldAttribute class, there is not a way to use interpolation with the NumberFormatPattern property. The NumberFormatPattern property simply lets you define the Google Sheets API defined format property of the cell. For full details of the various patterns you can use, see the link below. I'll also add these to the docs as well to make it easier to find in the future.

https://developers.google.com/sheets/api/guides/formats

For writing the header row you have a few options. I added a new method in the BaseRepository class just now (version 1.0.52) to include a method WriteHeaders which will append the header display names to the sheet. This will throw an exception if the HasHeaderRow is true.

// You need to implement your own configuration management solution here!
var settings = AppSettings.FromEnvironment();

// Create a SheetHelper class for the specified Google Sheet and Tab name
var sheetHelper = new SheetHelper<TestRecord>(
    settings.GoogleSpreadsheetId,
    settings.GoogleServiceAccountName,
    settings.GoogleMainSheetName);

sheetHelper.Init(settings.JsonCredential);

// Create a Repository for the TestRecord class
var repository = new TestRepository(sheetHelper, hasHeaderRow: false);

// Write the header display names to the Google Sheet tab
repository.WriteHeaders();

If you want to ensure the header columns are present, the best way to do that is to make sure you call the ValidateSchema method which will inspect the first row to make sure it has all the column header values.

Depending on what you are doing, you may also want to check out the SheetAppender class,

https://github.com/SteveWinward/GoogleSheetsWrapper#append-a-csv-to-google-sheets

Hope this helps.

ghost commented 1 year ago

Thank you very much for replying back, I have another question. How can I create a new sheet (not document, a sheet within same document) with your library? Thanks again.

Edit: UpdateTabName works like a charm, thank you.

SteveWinward commented 1 year ago

Check out the UpdateTabName method in the SheetHelper class. If you give it a tab name that downer exist it will create a new one for you. There’s also a private method that we could also make public to create a new tab in that class.

Hope that helps.

ghost commented 1 year ago

Seems like WriteHeaders() throws an exception when I set the flag to false, unless I'm doing something wrong.

Edit: After reviewing your change to the latest push, you're checking if "HasHeaderRow" is "False" and if it is "False" you're throwing the exception instead of checking if it's "True", could this be a mistake (bug)?

Also, how can I group rows by a specific property of the Record model? Would be helpful if you could allow us to group by a certain property of the model. I found this, might be interesting for you.

Edit: Do you think you could add the option to allow BBCode for "WriteHeaders()"? This would be awesome to make the headers in bold.

SteveWinward commented 1 year ago

@dahanj95 sorry for the delay. I built this library in my free time and I haven’t had a chance to review your latest comment. I suspect you are right. I quickly made a change hoping it would solve your issue I probably did the wrong logic.

I reopened the issue in case anyone in the community is able to fix this. Once I get more bandwidth I will try and take a look again.

Sorry you are dealing with this issue.

ghost commented 1 year ago

The error doesn't really bother me as I am instantiating the class with "True" on by default which bypasses the problem, but I'm really concerned with my other remarks. If you could state them that would be excellent, thank you.