1

trying to get all cell values (using Cell.Displayvalue) from a specific column in my sheet. I have already used the GetSheet method to pick specific column in sheet. I am not sure how to loop through this specific column and obtain the cell values. My goal is to use these values for a drop down menu in my C# application. I am lost in what lists/objects i need to make to obtain what I need.

Code Below:

 // Initialize client and get Token
            SmartsheetClient ss = new SmartsheetBuilder().SetAccessToken("b7y1brxa4rd8gmki6aa6zi6wr").Build();

            // List all sheets
            PaginatedResult<Sheet> sheets = ss.SheetResources.ListSheets(
                null,       //IEnumerable < SheetInclusion > includes
                null,       //PaginationParameters
                null        //Nullable<DateTime> modifiedSince = null
                );

            Console.WriteLine("Found " + sheets.TotalCount + " sheets");

            long sheetId = (long)sheets.Data[1].Id;    //default to first sheet

            long test = 8905499732141956;

            List<long> testList = new List<long>();
            testList.Add(test);

            // Load the entire sheet
            var sheet = ss.SheetResources.GetSheet(
                sheetId,           // long sheetId
                null,                       // IEnumerable<SheetLevelInclusion> includes
                null,                       // IEnumerable<SheetLevelExclusion> excludes
                null,                       // IEnumerable<long> rowIds
                null,                       // IEnumerable<int> rowNumbers
                testList,                       // IEnumerable<long> columnIds
                null,                       // Nullable<long> pageSize 
                null                        // Nullable<long> page
            );
            Console.WriteLine("Loaded " + sheet.Rows.Count + " rows from sheet: " + sheet.Name);
            Console.WriteLine("Loaded " + sheet.Columns.Count + " columns from sheet: " + sheet.Name);

            //PaginatedResult<Column> columns = ss.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
            //Cell[] celltest;

            foreach (Column column in sheet.Columns)
            {
                Console.WriteLine(column.Title + "    Column ID is " + column.Id);



            }

            List<Cell> val = new List<Cell>();
            List<Row> val2 = new List<Row>();


            foreach (Row row in sheet.Rows)
            {
                Console.WriteLine(row);
            }
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
Valentin
  • 21
  • 1
  • 6

1 Answers1

1

As described in How to read a sheet response, the column object defines the columns, and the actual cell data is stored in the rows.

See the sample csharp-read-write-sheet for sample code that loops through the rows of a sheet and examines the cell values in specific columns.

The SDK source has an even smaller sample that dumps the first few rows of a sheet. https://github.com/smartsheet-platform/smartsheet-csharp-sdk/blob/master/Sample/Program.cs

Steve Weil
  • 863
  • 5
  • 8