Google Spreadsheet Script: Is a sheet hidden or visible? - google-apps-script

In a custom Google Spreadsheet function, is there any way to determine if a sheet (tab) is hidden or visible?

Google has recently added the ability to hide and show sheets. To know whether the sheet is hidden, a new function isSheetHidden() has been added.

Unfortunatley Hide/Unhide classes for spreadsheets are unsupported. There is an open enhancement request. For hiding/showing sheets; you might like to star /comment it to be kept updated.

Related

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.
Retrieve the Spreadsheet chart.
Retrieve the image blob from the chart.
Insert the image blob by copying the size and place of the Spreadsheet chart.
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:
asImage()
insertImage(blobSource, left, top, width, height)
remove()
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.

To copy the cell text and the comments to another sheet using google apps script?

I have a google spreadsheet with comments in each cell. Can i programatically read, copy and the cell text and the comments to another sheet using google apps script? I need this facility with comments and not with notes.
Just discovered, that .moveTo(target) is able to move comments even between sheets.
You can read about it here: https://developers.google.com/apps-script/reference/spreadsheet/range#movetotarget
Hope this helps somebody.
This function will move a cell with its comments to a different sheet.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Original");
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Target");
sheet.getRange("A1").moveTo(targetSheet.getRange("A1"));
}
There is currently no way to interact with commends for Google Apps script.
You can follow this bug to see how the implementation of that is coming along (not very fast).

Attach a google form to a google spreadsheet

I'd like to create a form by google script.
This is pretty easy but I'd like to attached this form to a spreadsheet (no only the response), like I would have created it by the UI.
Is that possible ? Given the Formclass or FormApp is doesn't seem so. Is there a way around ?
EDIT: My goal was to create the form with the script and having the same result as if the user had had the form created from the UI interface (the main difference being having the form menu in the SS UI). It's apparently not possible.
You're right - it's pretty easy once you have the trick. Use FormApp to get the published URL of the form, UrlFetch to grab its html, then the HtmlService to present the form in the spreadsheet's UI.
See Single Google Form for multiple Sheets.

How to dynamically create buttons in cells with Google Apps Script for Spreadsheet?

I'd like to add buttons on a set of rows in a spreadsheet, and each of those buttons will call a function using that row's values.
Is this possible with Google Apps Script/Spreadsheets?
Now neither Google Spreadsheets nor GAS support controls in cells. There is a similar question here and a possible workaround for this issue.

Can I make my UiApp draggable?

Using Google Apps Script, I've made a UI for use on a Google Spreadsheet.
When called, it appears in the centre of the spreadsheet. I'd like to make it draggable so the user can move it out of the way if necessary - they may need to change cell selection whilst the UI is active.
Is this possible?
You should add a title, then you can drag it 'by the title' ;-)
example : app.setTitle("drag me here");