Last active
December 20, 2015 11:19
-
-
Save alextucker/6122465 to your computer and use it in GitHub Desktop.
Paste this into the Google App Script Editor
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
// 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