5

Does anyone know if there is a way to use the Google Sheets API to get the email address of a people chip? It seems like the only values it will give me are the person's full name as displayed in the cell.

While trying to figure this out I discovered that the name turns into an email address if you use "Format > Clear Formatting". I hoped I could hack this by copying the value into a hidden sheet, clearing the formatting, and then get the email address there. But though Google Apps Script has a function for executing that on a cell, I have found no way to do it with the Sheets API. I tried clearing all the possible formats I could via batchUpdate with an updateCellsRequest but that isn't turning the people chip into an email address.

I'm at the point where if I really want to automate this, I will need to use the scripts API as well, to deploy and execute a tiny Apps Script just to run clearFormat on a cell. I'd like to avoid this much complication, especially since Apps Script doesn't work for service accounts.

1
  • In the current stage, unfortunately, it seems that Sheets API cannot manage the smart chips. So how about reporting it to Google issue tracker as the future request? [Ref}(developers.google.com/issue-tracker)
    – Tanaike
    Commented Mar 25, 2022 at 23:57

2 Answers 2

6

As Tanaike mentioned this is not possible at the moment but there is already a feature request in the Google Issue tracker related to adding the people chips to the Sheets API. You can check the request here.

I would suggest posting a comment on it and explain why you are interested in this feature. Or if you think your request has a different approach you can also submit a new feature request for the Sheets API here.

1
1

There is no official API in AppScript but there is a way to do this. Use the Data Extraction feature in a formula to get the email address.

Let's say you have the Person smart chip in column A. Add a formula in column B =A1.email. This will extract the email address from column A and put the email address in column B.

You can hide this column if you wish and then access column B programmatically.

This example will programatically set the formula and return the email address for A1.

function extractEmailFromSmartChip() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Set the formula in B1 to extract email from Smart Chip in A1
  var formulaCell = sheet.getRange('B1');
  formulaCell.setFormula('=A1.email');
  
  // Wait for the formula to calculate
  SpreadsheetApp.flush();
  
  // Retrieve the calculated value from B1
  var email = formulaCell.getValue();
  
  // Log the extracted email
  Logger.log('Extracted Email: ' + email);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.