How can I select and copy a chart from a spreadsheet to a doc using Google Script? -


for example, have google spreadsheet contain chart, there way copy chart google doc (as image) using google script?

here code copy chart google spreadsheet document:

function sheetchart() {   try   {     var sheet = documentapp.getactivedocument().getbody().appendimage(mychart());   }   catch(err)   {     logger.log(err);   } }   function mychart() {     try     {       var data = charts.newdatatable()       .addcolumn(charts.columntype.number, 'month')       .addcolumn(charts.columntype.number, 'in store');        var sheet = spreadsheetapp.openbyid('spreadsheet id').getactivesheet().getrange(2,1,4,2).getvalues();        for(var =0;i< sheet.length;i++)data.addrow(sheet[i]);       data.build();        var chart = charts.newcolumnchart()                   .setdatatable(data)                   .setstacked()                   .setrange(0, 40)                   .settitle('sales per month')                   .build();      }catch(err){             logger.log(err);       }       return chart.getblob(); } 

data added in sheet is:

profitability   sales 11.00   10000 12.00   11000 13.00   12000 14.00   13000 

added code in document script editor , copying chart image in doc.

hope helps!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -