Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onOpen(e){
- SpreadsheetApp.getUi().createMenu('Utill')
- .addItem('Show Chart', 'entrypoint')
- .addToUi();
- }
- function entrypoint() {
- const ss = SpreadsheetApp.getActiveSpreadsheet();
- const tempSheet = ss.getSheetByName('TempData');
- const cell = ss.getActiveSheet().getActiveCell();
- const sheet = cell.getSheet();
- const ticker = sheet.getRange(cell.getRow(),1).getValue();
- const formulaRaw = /SPARKLINE\((.*?);{/g.exec(cell.getFormula())[1]
- const a1 = /GOOGLEFINANCE\((.*?);/g.exec(formulaRaw)[1];
- const formula = `=${formulaRaw.replace(a1,`"${ticker}"`)}`;
- console.log(formula);
- tempSheet.getRange(1,1).setValue(ticker);
- tempSheet.getRange(2,1).setFormula(formula);
- SpreadsheetApp.flush();
- Utilities.sleep(1000);
- createChart();
- }
- function getChartData(){
- const ss = SpreadsheetApp.getActiveSpreadsheet();
- const tempSheet = ss.getSheetByName('TempData');
- const data = tempSheet.getRange(3,2,tempSheet.getLastRow()-2).getValues().flat();
- const labels = tempSheet.getRange(3,1,tempSheet.getLastRow()-2).getValues().flat()
- .map(label => { return new Date(label).toLocaleDateString()})
- const ticker = tempSheet.getRange(1,1).getValue();
- return {ticker, data, labels};
- }
- function createChart(){
- const html = HtmlService.createHtmlOutputFromFile("chart");
- html.setHeight(500).setWidth(800);
- SpreadsheetApp.getUi().showDialog(html);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement