Created
August 27, 2020 02:56
-
-
Save rheajt/678bc7ad66293e278861b75dce8abff3 to your computer and use it in GitHub Desktop.
[Replace Links] grab a drive link from a spreadsheet and replace it with an embeddable url #gsuite #gas #sheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceLinks() { | |
const trainingSheet = SpreadsheetApp.getActive().getSheetByName('Data'); | |
const trainingRange = trainingSheet.getRange(3, 3, trainingSheet.getLastRow() - 2); | |
const values = trainingRange.getValues(); | |
values.forEach(([link], ind) => { | |
const matches = /\/([\w-_]{15,})\/(.*?gid=(\d+))?/.exec(link); | |
if(!matches) { | |
return; | |
} | |
values[ind] = ['https://drive.google.com/uc?export=view&id=' + matches[1]]; | |
}); | |
console.log(values); | |
trainingRange.setValues(values); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment