Excel Match function not working properly with the MS-Graph API

179 Views Asked by At

When sending a match-function post request to an Excel workbook with the MS-Graph API I'm not recieving the value of the first column that contains the lookup value but of the second column that does.

let functionArgs = {
lookupValue: userID,
lookupArray: { Address: "Tabelle1!A2:CZ2" },
lookupType: 0
};
let body = JSON.stringify(functionArgs);
try { 
await this.graphClient  
.api(`${this.url}/drives/${driveID}/items/${itemID}/workbook/functions/match`)
.post(body , (err, res) => {

The Callback function of the post request returns the number of the second column containing the lookup value. If there is only one column containing the lookup value the post returns with "error: #N/A", indicating that the match function couldn't find the lookup value within the given range.

I'm doing the exact same with dates and it's working fine.

1

There are 1 best solutions below

0
Sarwar On

Change lookupType argument to matchType and it should work, snippet below.

   let functionArgs={

      "lookupvalue": "Sarwar Rana",
      "lookuparray": { "Address": "Sheet1!A1:A12" },
      "matchtype": 0

    };

    let body = JSON.stringify(functionArgs);

    return new Promise<any>((resolve, reject) => {
      try {
        this.context.msGraphClientFactory
          .getClient()
          .then((client: MSGraphClient) => {
            client
            .api('/me/drive/root:/Clients.xlsx:/workbook/functions/match')
              .post(body)
              .then((lookupResponse) =>{
                  console.log(lookupResponse.value);
              });
          });
      } catch(error) {
        console.error(error);
        reject(error);
      }
    });