Search code examples
c#smartsheet-apismartsheet-c#-sdk-v2

How to get cell's column type in smartsheet


I'm trying to get column type information from cells when I call GetSheet(), using Smartsheet API with C# and most of the time it's null. I read in the documentation that I can do that but am not understanding.

Endpoints which return rows (e.g. get sheet, get row) support the optional include query string parameter. http://smartsheet-platform.github.io/api-docs/#row-include-flags

I'm not seeing an option to add the column type in my intellisense. Am I missing something? enter image description here

I'm using the latest Smartsheet SDK 2.0.1.0.


Solution

  • Column type information is returned by default for the GetSheet() operation, so you don't need to specify any inclusion flag when making the call. (That's why you're not seeing an option for it in your intellisense.)

    The following code snippet shows how to use the C# SDK to retrieve a Sheet and iterate through the columns in the sheet, printing the Title and Type of each column:

    // Set the Access Token
    Token token = new Token();
    token.AccessToken = YOUR_ACCESS_TOKEN;
    
    // Use the Smartsheet Builder to create a Smartsheet
    SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build();
    
    // Get Sheet
    long sheetId = YOUR_SHEET_ID;
    Sheet sheet = smartsheet.SheetResources.GetSheet(sheetId, null, null, null, null, null, null, null);
    
    // Examine columns and write Title and Type for each column.
    foreach (Column column in sheet.Columns)
    {
        Response.Write(column.Title + ": " + column.Type.ToString() + "<br/><br/>");
    }
    

    Please note that there is currently a known issue (bug) with the C# SDK -- Column.Type is not being populated in the GetSheet() response for the 3 special column types that are present only in dependency-enabled project sheets: DURATION, PREDECESSOR, ABSTRACT_DATETIME (i.e., start date and end date). There's no ETA for resolution of this issue at this time. However, you could fix it yourself by downloading the C# SDK source code from GitHub and updating the ColumnType Enumeration to add the 3 missing enum values:

    • DURATION
    • PREDECESSOR
    • ABSTRACT_DATETIME