I'm trying to update my SmartSheet API from v1 to v2 and am having some difficulty on the code below.
The code returns rows for the selected sheet, however the "ColumnType" property of all the Cell's within the rows are NULL.
I know to return this you have to specify it as an inclusion - which I believe I have.
Dim sheet As Sheet = smartsheet.SheetResources.GetSheet(curSheet.Id, New RowInclusion() {RowInclusion.COLUMN_TYPE, RowInclusion.COLUMNS}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
For Each Row As Row In sheet.Rows
If Row.ParentRowNumber Is Nothing Then
Dim i As Integer = 0
Dim colType As ColumnType
If Not Row.Cells(i).ColumnType = ColumnType.TEXT_NUMBER Then
'Do some stuff here...
End if
Next
Any help would be great.
Thanks, Steve
The short answer is just get the latest SDK from https://github.com/smartsheet-platform/smartsheet-csharp-sdk/pull/60 and update your GetSheet to the following:
Dim sheet As Sheet = client.SheetResources.GetSheet(SHEETID, New SheetLevelInclusion() {SheetLevelInclusion.COLUMN_TYPE}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
Notice the use of SheetLevelInclusion
rather than RowInclusion
. You should be all set.
If you care about the details, the longer answer is... The GetSheet
method doesn't accept an array/IEnumerable of RowInclusion
as the second argument. It expects an array/IEnumerable
of SheetLevelExclusion
. In C#, the same invocation call would fail as C# imposes stricter type checking on the generic type parameter of IEnumerable
. However, due to Visual Basic's leniency around implicit conversions between Enum
types and its lenient conversions for arrays (and similar types like IEnumerable
) it is possible to invoke a function with the "wrong" type of argument when the argument is an array/IEnumerable
and the elements are Enums. In this case, Visual Basic is actually converting the RowInclusion
values to their underlying numeric value (Enum is always implicitly or explicitly backed by an underlying numeric type) and converting those values to the SheetLevelExclusion
value corresponding to the same underlying numeric value so that it can invoke the GetSheet method.
The other complication here is that the SDK didn't have COLUMN_TYPE as an available SheetLevelExclusion
value. So the pull request/branch I linked to above adds that. In my simple test here that made it work.