title: Update Values in Excel Named Ranges using Microsoft Graph API
body: <p>I have an Excel file loaded into Office 365 that is accessible via the Microsoft Graph API with many named ranges, some are individual values, some are blocks of cells.</p>
  
  <p>I can successfully update individual values using the API, but when I try to update multiple cells at the same time, I run into problems.</p>
  
  <p>For this example, consider a single 3-cell array from <code>F10:F12</code></p>
  
  <p>I would like to populate as follows:</p>
  
  <p><code>F10</code> = <code>A</code></p>
  
  <p><code>F11</code> = <code>B</code></p>
  
  <p><code>F12</code> = <code>C</code></p>
  
  <p>So, I create list of strings that ends up looking like this...
  <code>[ ["A"], ["B"], ["C"] ]</code></p>
  
  <p>and I pass it to the Graph API using the following code...</p>
  
  <pre><code>public static async Task&lt;WorkbookRange&gt; UpdateRangeArray(string strItemId, string strSheetName, string strRangeName, List&lt;string&gt; strRangeValues, string strSessionId)
  {
      string[][] strValueArray = new string[strRangeValues.Count][];
      try
      {
          int i = 0;
          foreach (var val in strRangeValues)
          {
              strValueArray[i] = new string[1] { val };
              i++;
          }
      }
  
      var jsonValueArray = JsonConvert.SerializeObject(strValueArray);
  
      var rangeUpdate = new Microsoft.Graph.WorkbookRange();
      rangeUpdate.Values = jsonValueArray;
  
      var result = await graphClient.Users[_strUserId].Drive.Items[strItemId].Workbook.Worksheets[strSheetName]
          .Range(strRangeName)
          .Request()
          .Header("workbook-session-id", strSessionId)
          .PatchAsync(rangeUpdate).ConfigureAwait(false);
  
      return result;
  
   }
  </code></pre>
  
  <p>So I am able to update the values in the range, EXCEPT instead of the expected values, what I get is this...</p>
  
  <p><code>F10</code> = <code>[ ["A"],["B"],["C"] ]</code></p>
  
  <p><code>F11</code> = <code>[ ["A"],["B"],["C"] ]</code></p>
  
  <p><code>F12</code> = <code>[ ["A"],["B"],["C"] ]</code></p>
  
  <p>Instead of the Graph API putting the first value in the first cell, second value in the second cell, and so forth... It puts the entire array of data in each cell.</p>
  
  <p>I assume this is some sort of formatting error, maybe my JSON is malformed or perhaps I'm submitting it using the wrong Graph API endpoint or something.</p>
  
  <p>Any help would be greatly appreciated...</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I also tried doing this with the RANGE (ie - <code>.Range("F10:F12")</code>) instead of using the NAME and I get the same result.</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Cross-posted on GitHub in case this is a bug not just a user error.
  <a href="https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/695" rel="nofollow noreferrer">https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/695</a></p>
  
  <p><strong>UPDATE 3:</strong></p>
  
  <p>I can successfully PATCH via the Graph API Explorer to the following URL...
  <a href="https://graph.microsoft.com/v1.0/me/drive/items/" rel="nofollow noreferrer">https://graph.microsoft.com/v1.0/me/drive/items/</a>{item-id}/workbook/worksheets/INPUTS/range(address='F10:F12')</p>
  
  <p>with this body...
  <code>{"values":[["Hello"],["How"],["Are You?"]]}</code></p>
  
  <p>...and it works.</p>
  
  <p>but still can't get it to work via the <a href="https://github.com/microsoftgraph/msgraph-sdk-dotnet" rel="nofollow noreferrer">MSGraph-SDK-dotnet</a></p>
  
  <p><strong>UPDATE 4:</strong></p>
  
  <p>I AM able to get it to work correctly using Postman and the resulting RestSharp code that works looks like this...</p>
  
  <pre><code>    public static async Task TestUpdatePostman()
      {
          var client = new RestClient("https://graph.microsoft.com/v1.0/users/{USER-ID}/drive/items/{ITEM-ID}/workbook/worksheets/INPUTS/range(address='F10:F12')");
          client.Timeout = -1;
          var request = new RestRequest(Method.PATCH);
          request.AddHeader("Authorization", "Bearer {INSERT-TOKEN}");
          request.AddHeader("Content-Type", "application/json");
          request.AddParameter("application/json", "{\"values\":[[\"Hello\"],[\"How\"],[\"Are You?\"]]}", ParameterType.RequestBody);
          IRestResponse response = client.Execute(request);
          Console.WriteLine(response.Content);
      }
  </code></pre>
  
  <p>This again makes me believe there's an issue with the way the SDK wrapper implements the API call.</p>