Skip to content

Instantly share code, notes, and snippets.

@alextucker
Last active December 20, 2015 11:19
Show Gist options
  • Save alextucker/6122465 to your computer and use it in GitHub Desktop.
Save alextucker/6122465 to your computer and use it in GitHub Desktop.
Paste this into the Google App Script Editor
// Get UI Context
var ui = DocumentApp.getUi();
function onOpen(){
ui.createMenu('Stocks').addItem('Add Stock Info', 'addStockInfo_').addToUi();
}
// Handle Menu Item
function addStockInfo_(){
// Prompt user and get result
var result = ui.prompt('Enter Ticker Symbol');
// Get stock info based on result
var stockInfo = FinanceApp.getStockInfo(result.getResponseText());
// Prepare table of data
var data = [
['Stock', stockInfo.name],
['Price', stockInfo.price],
['Volume', stockInfo.volume]
]
var body = DocumentApp.getActiveDocument().getBody();
var table = body.appendTable(data);
// Bold the first column of the table
for(var i=0; i < data.length; i++) {
table.getRow(i).getCell(0).editAsText().setBold(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment