I have a Google Sheet with anizations and their addresses as Smart Chips from Google Maps in Column E. I want to copy each address into column L as text (Not a Smart Chip) so that my team can do a mail merge of the addresses onto envelopes. Instead of manually copying and pasting the addresses within the Smart Chips, is there a way to do this automatically?
I tried using Google's Apps Script to extract the address. I ran the script below and the execution was completed, but nothing happened in my Sheet. Here is a sample sheet where you can see that Column L is blank despite having run the script:
function extractAddress() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getDataRange(); // This checks all data in the sheet, you can modify it to a specific range
// Loop through all cells in the sheet
for (var i = 0; i < range.getNumRows(); i++) {
for (var j = 0; j < range.getNumColumns(); j++) {
var cell = range.getCell(i + 1, j + 1);
var richText = cell.getRichTextValue();
// Check if the cell contains Smart Chip data (such as a location link or an address)
if (richText) {
var smartChip = richText.getLinkUrl();
// If a link is present, it's most likely a Smart Chip with an address or a location
if (smartChip) {
Logger.log("Found Smart Chip: " + smartChip); // Logs the Smart Chip value (for debugging)
// Output the Smart Chip (address or link) to the next column
sheet.getRange(i + 1, j + 2).setValue(smartChip); // Outputs to the next column
}
}
}
} }