Get row data from smartsheet in C #

I hope I can get the rows of data as a list of specific columns in C #. Therefore, if there was a column of heights of a person, he would list these heights in the list. It is also possible to list the values ​​of x, y, for example, the number of apples on a certain date.

I looked at examples of the API data and cannot find examples of how to do this - they mainly consist of creating folders, users, or listing folders or sheets, or entering information about smartsheets, etc., but no one actually gets the data.

Here is the code I was looking at: https://github.com/smartsheet-platform/samples/tree/master/c%23 https://github.com/smartsheet-platform/smartsheet-csharp-sdk

But I really would like to pull the data in a list, and then process it a bit in C # for end users, so I don't want to return it to smartsheets.

Is this the only way to do this, to download the file as an Excel worksheet using the API and from there? Did I really want to skip this step, if at all possible?

I must add that I want to use the C # SDK for this.

The specific code that I think I need to enter (I think) is to get the sheet.

// Set the Access Token Token token = new Token(); token.AccessToken = "INSERT_YOUR_TOKEN_HERE"; long id = "INSERT SHEET ID HERE"; // Use the Smartsheet Builder to create a Smartsheet SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken( token.AccessToken).Build(); //Code to get sheet smartsheet.Sheets().GetSheet(long id, **IEnumerable<ObjectInclusion?includes**).Rows(); 

This is the last parameter that I'm not sure what they need. He says in the GetSheet method:

GetSheet (long identifier, IEnumerable includes)

Here is a link to the ObjectInclusion enumeration - http://smartsheet-platform.imtqy.com/smartsheet-csharp-sdk/html/T_Smartsheet_Api_Models_ObjectInclusion.htm

+5
source share
1 answer

Here is an example that prints cell data on each sheet.

  // Set the Access Token Token token = new Token(); token.AccessToken = "YOUR_TOKEN"; // Use the Smartsheet Builder to create a Smartsheet SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build(); // Gets just a list of sheets (not the actual data in the sheet) IList<Sheet> homeSheets = smartsheet.Sheets().ListSheets(); foreach (Sheet tmpSheet in homeSheets) { Console.WriteLine("========== New Sheet: " + tmpSheet.Name); // Get the sheet with the data Sheet sheet = smartsheet.Sheets().GetSheet((long)tmpSheet.ID, new ObjectInclusion[] { ObjectInclusion.DATA, ObjectInclusion.COLUMNS }); int rowCount = 0; foreach (Row tmpRow in sheet.Rows) { Console.Write(rowCount++ + ": "); foreach (Cell tmpCell in tmpRow.Cells) { Console.Write(tmpCell.Value + "|"); } Console.WriteLine(); } } 

To answer your other questions:

Is this the only way to do this, to download the file as an Excel worksheet using the API and from there? Did I really want to skip this step, if at all possible?

The C # SDK and API both support the ability to retrieve parts or all sheet data. You are not required to download the sheet as an Excel file in order to work with the data in the sheet.

I'm not sure what they need. He says in the GetSheet method: GetSheet sheet (long id, IEnumerable <ObjectInclusion>)

An IEnumerable is just a collection that is iterable. You can use any collection for the second parameter that implements this interface. The collection should contain the ObjectInclusion elements in this list. In my example, I used an array because it implements IList , which implements IEnumerable.

+5
source

Source: https://habr.com/ru/post/1208380/


All Articles