简体   繁体   中英

Google Slides & Apps Script: Unlink all embedded sheet charts

I'm publishing Google Slides containing a lot of embedded charts coming from a Spreadsheet. I would like to unlink the embedded charts (and thus avoid to get the update button when the data are updated in the spreadsheet). If google proposes to update all elements at once through the "Linked objects" entry of the Tools menu, there is no option to unlink all in one shot. I would need to go on each chart and select unlink.

So I'm looking now the option of writing a Google Apps Script to do that without success.

I found a similar question on stackoverflow here: Remove all hyperlinks of a Google Slide using GAS

But the removeLink function does not have any effect on my chart. I still see the chained icon on the top right corner.

Any idea?

Unfortunately, it seems that in the current stage, there are no methods for directly removing the link to Spreadsheet from Speadsheet. But when the link to Spreadsheet from Speadsheet chart is removed, it is found that the object becomes an image. I thought that this might be used for achieving your goal. So, from this situation, as a workaround, I would like to propose the following sample script.

Sample script:

This sample script converts the Spreadsheet chart to an image on the 1st slide. By this flow, the link to Spreadsheet from Speadsheet chart is removed.

const slide = SlidesApp.getActivePresentation().getSlides()[0];
const charts = slide.getSheetsCharts();
const chart = charts[0];
slide.insertImage(chart.asImage().getBlob(), chart.getLeft(), chart.getTop(), chart.getWidth(), chart.getHeight());
chart.remove();
  • The flow of this script is as follows.

    1. Retrieve the Spreadsheet chart.
    2. Retrieve the image blob from the chart.
    3. Insert the image blob by copying the size and place of the Spreadsheet chart.
    4. Remove the Spreadsheet chart.

Note:

  • This sample script copies the size and place. When you want to copy other values, please modify the script.

References:

Added:

About your additional question as follows.

I think this is a good workaround for charts (such as pie charts, column... that can be converted as images). Nevertheless, I have some slides where I have some cells embedded. Running this code on this element is displaying an issue. Do you think this also feasible on embedded tables?

The chart is different from the table. So in this case, I think that your additional question is new question.

Your initial question is for removing the Spreadsheet link from the chart. My answer is for your this question. In this case, the table cannot be used. And, in the current stage, unfortunately, there are no methods for removing the link of Spreadsheet from the table. And also, when the Spreadsheet link is removed from the table, the object type is not changed from the table. By this, my workaround cannot be used. But Slides service and Slides API are growing now. So I think that such method might be added in the future update.

So, as the current method, how about reporting your new question to Google issue tracker ? By this, the addition of such method might be considered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM