|
/** |
|
* https://developers.google.com/apps-script/service_spreadsheet |
|
*/ |
|
function createDestinationUrl() { |
|
var sheet = SpreadsheetApp.getActiveSheet(); |
|
var rows = sheet.getDataRange(); |
|
var numRows = rows.getNumRows(); |
|
var values = rows.getValues(); |
|
|
|
for (var i = 0; i <= numRows - 1; i++) { |
|
var cell = rows.getCell(i+1, 2); |
|
cell.clearContent(); |
|
// Replace with desired destination URL. |
|
cell.setValue('http://journalism.howlround.com/' + rows.getCell(i+1, 1).getValue()); |
|
// Logger.log(row); |
|
} |
|
}; |
|
|
|
|
|
function createOriginUrl() { |
|
var sheet = SpreadsheetApp.getActiveSheet(); |
|
var rows = sheet.getDataRange(); |
|
var numRows = rows.getNumRows(); |
|
rows.copyTo(sheet.getRange(1, 2)); |
|
|
|
for (var i = 0; i <= numRows - 1; i++) { |
|
var cell = rows.getCell(i+1, 1); |
|
var value = cell.getValue(); |
|
// Replace with origin URL. This should match the contents of the CSV. |
|
value = value.replace('http://www.howlround.com/', ''); |
|
cell.setValue(value); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* Adds a custom menu to the active spreadsheet, containing a single menu item |
|
* for invoking the readRows() function specified above. |
|
* The onOpen() function, when defined, is automatically invoked whenever the |
|
* spreadsheet is opened. |
|
* For more information on using the Spreadsheet API, see |
|
* https://developers.google.com/apps-script/service_spreadsheet |
|
*/ |
|
function onOpen() { |
|
var sheet = SpreadsheetApp.getActiveSpreadsheet(); |
|
var entries = [{ |
|
name : "Create destination URL", |
|
functionName : "createDestinationUrl" |
|
}, |
|
{ |
|
name : "Create origin URL", |
|
functionName : "createOriginUrl" |
|
} |
|
]; |
|
sheet.addMenu("Scripts", entries); |
|
}; |