App Scrips do not copy a Chart properly

162 views
Skip to first unread message

Roberto Robas

unread,
Mar 2, 2023, 8:09:57 AM3/2/23
to Google Apps Script Community
Hi, 

My problem is the next one.
I have developed a App Script in order to retrieve some information from a SpreedSheet document and convert them into a pdf file.

In this document, I have a sheet with several graphs based on the rest of the sheets.
I need some information from other sheets and one of these graphs.

My issue is when I try to copy this graph, Apps Script copy it without conserve the format I have given to the chart. 

In the spreedSheet I can see this graph:

okChart.png

But in my final pdf file, the same graph appears like this:

failChart.png

As you can see, the custom format applied (0;-0;;@), used to hide zero values is not copied properly in the pdf file.

To obtain this chart I use the following code:

  var charts = sheet.getCharts();
var chart = charts[index];
 var imageData = chart.getAs('image/png');
 copyDoc.getBody().appendImage(imageData);

Please, tell me what I am doing wrong or how can I get a exact image in the pdf file from the SpreedSheet document. 

Thanks.

cwl...@gmail.com

unread,
Mar 2, 2023, 10:37:35 AM3/2/23
to Google Apps Script Community
I had this problem too a couple years ago. I will try to find if I ever found a solution.

cwl...@gmail.com

unread,
Mar 2, 2023, 11:26:47 AM3/2/23
to Google Apps Script Community

Roberto Robas

unread,
Mar 3, 2023, 4:40:04 AM3/3/23
to Google Apps Script Community
Thank you so much but this solution is not working for me. :( 
Reply all
Reply to author
Forward
0 new messages