You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to figure out how to filter Excel table rows via MSGraph (v5).
With the evolution of MSGraph through different versions (Now V5), there is a lot of outdated and conflicting information out there that my searching has uncovered. To be clear, I am trying to do this all with msgraph-sdk-dotnet
In my searching I have seen suggestions for two main methods.
#1
Some posts I have read suggest using msgraph filter in the query...
i.e. ..... /workbook/tables/Table1/rows ? $filter=NameCol eq 'Frank'
(I haven't had any success getting this to work, and my guess is that this is bad information and not a viable method)
#2
others say the only way is to use MSGraph to apply a column filter IN excel, then retrieve the 'visible rows' and then clear the filter, ideally using a workbook-session-id and a persist-changes=false to isolate other users from seeing / being affected by your filter manipulation etc via the API.
Obviously the easiest ideal way would be to handle it via #1, but my experimentation with MS Graph explorer and method #1 seems to be a bust? Is that a correct assessment?
Part two of the question..
Using method #2- Lets say I want to filter all the rows of a table on a column 'Name' with a value of 'Frank'. Once I have all of those rows with 'Frank', I want to update another cell in each of those rows, and save it back to the worksheet..
It seems that you would:
a) Apply the column filter to the worksheet
b) Retrieve the filtered rows with ...Tables/tablename/DataBodyRange/VisibleView (returns a WorkBookRangeView)
c) Now I want to update a cell of each of those returned 'filtered' rows.
d) Now I want to write them back to the spreadsheet.
// Define our column filter
var requestBody = new Microsoft.Graph.Drives.Item.Items.Item.Workbook.Tables.Item.Columns.Item.Filter.Apply.ApplyPostRequestBody
{
Criteria = new WorkbookFilterCriteria
{
Color = null,
Criterion1 = "=Frank",
Criterion2 = null,
FilterOn = "Custom",
DynamicCriteria = "Unknown",
Operator = "Or",
Icon = null,
Values = null
},
};
// Apply the Column filter to the Column 'Name'
await GraphClient
.Drives[SpreadsheetIdentifier.DriveID]
.Items[SpreadsheetIdentifier.SpreadsheetID]
.Workbook
.Tables[SpreadsheetIdentifier.TableName]
.Columns["Name"]
.Filter
.Apply
.PostAsync(requestBody,
(requestConfiguration) => {
requestConfiguration.Headers.Add("workbook-session-id", WorkbookSessionId!); });
// Retrieve the filtered Rows
// retrieve data
var kiotaData =
await GraphClient
.Drives[SpreadsheetIdentifier.DriveID]
.Items[SpreadsheetIdentifier.SpreadsheetID]
.Workbook
.Tables[SpreadsheetIdentifier.TableName]
.DataBodyRange
.VisibleView
.GetAsync((requestConfiguration) => {
requestConfiguration.Headers.Add("workbook-session-id", WorkbookSessionId!); });
Now I deserialize the rows from the kiotaData var into my strongly typed objects using System.Text.Json from kiotaData.Values
I manipulate my strongly typed objects.
Now I need to write them back to the Workbook.
The only way I am aware to 'update' existing rows in the Worksheet is essentially using a Range object. That means I will need the RowIndex for each of those 'filtered rows ' returned. There will be gaps between the 'filtered' rows. I basically build a JSON representing the Rows Data and use [null, null, ... null] for the gap rows (filtered rows) that I am not updating. But I need to know the range, and RowIndexes...
I should be able to issue a patch worksheets/{workbookWorksheetNameOrId}/range (address='{address}' graph call, but as of today it is missing from the SDK...
so I'm using aoisupersix workaround (#1873 (comment)) to do it.
I am able to grab the RowIndexes for the returned FilteredRows by snagging it from kiotaData.CellAddresses , but it seems so roundabout.
Sorry if I am being confusing, but assuming that you understand my question, am I going about this the right way or am I missing a simpler and more appropriate, straightforward, sdk friendly way to do this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been trying to figure out how to filter Excel table rows via MSGraph (v5).
With the evolution of MSGraph through different versions (Now V5), there is a lot of outdated and conflicting information out there that my searching has uncovered. To be clear, I am trying to do this all with msgraph-sdk-dotnet
In my searching I have seen suggestions for two main methods.
#1
Some posts I have read suggest using msgraph filter in the query...
i.e. ..... /workbook/tables/Table1/rows ? $filter=NameCol eq 'Frank'
(I haven't had any success getting this to work, and my guess is that this is bad information and not a viable method)
#2
others say the only way is to use MSGraph to apply a column filter IN excel, then retrieve the 'visible rows' and then clear the filter, ideally using a workbook-session-id and a persist-changes=false to isolate other users from seeing / being affected by your filter manipulation etc via the API.
Obviously the easiest ideal way would be to handle it via #1, but my experimentation with MS Graph explorer and method #1 seems to be a bust? Is that a correct assessment?
Part two of the question..
Using method #2- Lets say I want to filter all the rows of a table on a column 'Name' with a value of 'Frank'. Once I have all of those rows with 'Frank', I want to update another cell in each of those rows, and save it back to the worksheet..
It seems that you would:
a) Apply the column filter to the worksheet
b) Retrieve the filtered rows with ...Tables/tablename/DataBodyRange/VisibleView (returns a WorkBookRangeView)
c) Now I want to update a cell of each of those returned 'filtered' rows.
d) Now I want to write them back to the spreadsheet.
Now I deserialize the rows from the kiotaData var into my strongly typed objects using System.Text.Json from kiotaData.Values
I manipulate my strongly typed objects.
Now I need to write them back to the Workbook.
The only way I am aware to 'update' existing rows in the Worksheet is essentially using a Range object. That means I will need the RowIndex for each of those 'filtered rows ' returned. There will be gaps between the 'filtered' rows. I basically build a JSON representing the Rows Data and use [null, null, ... null] for the gap rows (filtered rows) that I am not updating. But I need to know the range, and RowIndexes...
I should be able to issue a patch worksheets/{workbookWorksheetNameOrId}/range (address='{address}' graph call, but as of today it is missing from the SDK...
so I'm using aoisupersix workaround (#1873 (comment)) to do it.
I am able to grab the RowIndexes for the returned FilteredRows by snagging it from kiotaData.CellAddresses , but it seems so roundabout.
Sorry if I am being confusing, but assuming that you understand my question, am I going about this the right way or am I missing a simpler and more appropriate, straightforward, sdk friendly way to do this?
Beta Was this translation helpful? Give feedback.
All reactions