Unable to extract link text from tooltip in Google Spreadsheet - google-apps-script

I'm optimistic this question has already been answered. But if not, I'm hopeful that one of you JavaScript and Google Script experts can lend some assistance.
Steps to Reproduce
Go to www.nhl.com/stats/player
Copy the top few rows in the table (see screenshot #1)
Paste the contents into a new Google Spreadsheet
Click on the name of a player in the "Player" column (see screenshot #2)
Notice that the name itself is shown in the formula bar while the tooltip has a link to the player's profile on nhl.com
What I Want to Happen
I'd like to extract the link content that's shown in the toolip. (In screenshot #2 this is referring to the https://www.nh...layer/8471215 text.)
What Actually Happens
Nothing really. There's no way to see the tooltip content in the formula bar and, as far as I can tell, there's no function (e.g. hyperlink) to extract the tooltip content.
Screenshots
Screenshot #1
Screenshot #2
Other Notes
I'm comfortable coding in JavaScript, but I have minimal experience in the script editor.

In addition to what Anton has said, Apps Script has only support for A1 Notation and R1C1 formulas for now:
getFormulas()
Returns the formula (A1 notation) for the top-left cell of the range,
or an empty string if the cell is empty or doesn't contain a formula.
getFormulaR1C1()
Returns the formula (R1C1 notation) for a given cell, or null if none.

Related

Google Sheets: Why can't I insert a link (to anything) in a cell containing a formula

In any Google Sheet, select a cell containing a formula, for example, =SUM(1,1). You'll see that both the Insert->Link menu
and the toolbar button for Insert Link (Ctrl + K) are disabled.
Why is that?
PS:
I've spent considerable time on Google, but I haven't found this issue mentioned anywhere.
This problem occurs irrespective of whether the formula has been manually typed in the cell or been populated through Apps Script.
This is intended behaviour
If you press Ctrl+K when a cell with a formula is highlighted you get the following message:
Not sure if this applies to you, but I solved my problem after coming here. I realized that where I was trying to change the links was actually an "importrange" of another file. So I have a daily sales ticker that feeds out to our salespeople, but I don't want them to "see" my live file and accidentally make changes. So I use "importrange" to show just one page of my big file to the salespeople and if they accidentally make a change, it doesn't affect my original formulas. I was trying to update the links on the "shared version". Once I went to my original file, I could update the links as expected. It was ODD though that I was able to delete the link on the shared page. Just couldn't edit it or create a new link there.

Activating a new cell not working within Google Sheets onSelection(e) execution?

Is there some way to force the selection of another cell (e.g. A1) after someone has selected a different cell (e.g. B2)? If i use a simple ...getRange(1,1).activate() code, it works when I hit "Run" in the script editor, but not when a selection is made in the real spreadsheet. Please help?
I've basically written a long "onSelection" code that allows someone to mark their answers to a trivia game as "Correct" or "Wrong" by clicking on the corresponding cells. (I do this with onSelection(e) because buttons don't work on mobile.)
However, if they get two answers correct in a row, onSelection(e) doesn't work because they've already selected "Correct" the first time. I want the code to select 'A1' automatically so it's ready for their next Correct/Wrong input.
A code as simple as the following works when I select any cell in Google Sheets and then hit "Run" in the script editor, but it doesn't not work when I select a cell with my mouse.
function onSelectionChange(e){
var sheet = SpreadsheetApp.getActiveSheet()
sheet.getRange(1,1).activate();
}

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.

Google Sheets - Track Current Cell Selection?

How to Get the currently selected cell/range? was asked 3.5 years ago, but I'm hoping maybe some progress was made since then.
I'd like to make an interactive spreadsheet where there's a boolean grid that will display more information about the status of the currently selected cell in a static location, allowing users to quickly navigate using the arrow keys.
Referencing the previous instance of this question, I tried using the custom function below to get the cell address, although this isn't very dynamic.
function currentCell() {
return SpreadsheetApp.getActive().getActiveRange().getA1Notation();
}
When testing, this function returns the address of the cell the function is called from. I've tried pressing F5 while highlighting another cell and nothing happened. I've also dragged the formula across a selection and each cell only contains its own address (according to the documentation, it should contain the range).
I've also read Henrique's post on caching from 2012, and while I don't completely understand it, I get that we could not get scripts which update without edits being made or manual formula updates.
I would ideally like for the current cell to be tracked without any extra prompts from the user besides arrow key navigation or clicking to select a cell, but if pressing a non-altering key (like Enter) would allow for tracking, that would be fine. I also only need the selected cell, rather than a range, if that makes things easier.
Explicit Question: Is it possible to track the position of the currently selected cell in Google Sheets and store that position in a separate cell? If not, is there a way to do this without altering cell values?
EDIT: Adding an example for clarity. In this conceptual example, A2 =currentCell() as described above. If I were to hit the right arrow key, A2 would update to display I4, since it is now the current selection.
EDIT2: Jason Allshorn's response to Google app script monitor spreadsheet selected ranges appears to give a way of displaying the current selection (range) on the HTML input text. I'd like to do this, but store the value in a static cell on the sheet rather than input text. I'm new to scripting in Sheets and really only know what I've found for resolving this issue, so if I'm overlooking something, please let me know. I did look at Jason's example sheet and it wasn't clear to me what was actually happening there.
You will have to apply the technique suggested on How do I make a Sidebar display values from cells?. This consist on using using client-side code to constantly pulling values from the spreadsheet and then do the corresponding task.
One approach is to use a side-panel with an input field to set the cells to be tracked and another input field to set the destination cell.
You will have to use the onSelectionChange event in the app script to capture any selection change and then get the range name and put it in desired cell.
Something like the below:
function onSelectionChange(e) {
const range = e.range;
//Return in case of multi cell selection
if(range.getNumRows() !== 1 || range.getNumColumns() !== 1) return;
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A2").setValue(range.getA1Notation());
}
You can see the official documentation here

How can I create a hyperlink in the middle of cell text? [duplicate]

This question already has answers here:
How can I create a hyperlink in the middle of cell text using a formula?
(3 answers)
Closed 1 year ago.
In google spreadsheets, it is possible to add a hyperlink to a cell as:
=hyperlink("www.google.com", "search the web")
This will show the text search the web which will hyperlink to google. However, I am wondering:
How can this rule be inserting into the middle of a cell? In other words, I'd like a single cell to look like:
click here for answer
As of now (June, 2020), it is possible to do what you described. Here is an official documentation.
Shortly:
Select part of text where you want to add a link, then click Insert -> Link or using shortcuts - CMD + K/CTRL + K. Personally, when I was clicking Insert from menu bar, my text was deselected, so shortcut solved the issue.
Extra Note: You can also link to other cells or sheet in a spreadsheet. Really cool feature.
EDIT (2020-Aug-06):
Google Sheets now supports this; see Aibol Kussain's answer.
Original answer:
As far as I can tell, Google Sheets [still] simply does not support what you are asking for. (I've looked around for it, too.)
See, e.g., https://docs.google.com/document/preview?hgd=1&id=1x_qjPL5rmSuQWW57KcwB9lg3eiykKpd8dMEaQUZbWU8, particularly where it says:
Please note: Like the other types of data and cell formatting, links in spreadsheets must be assigned to an entire cell, you cannot have just part of the text inside a cell be hyperlinked.
Also:
https://webapps.stackexchange.com/questions/24931/a-way-to-add-text-before-your-hyperlink-in-google-spreadsheets
https://webapps.stackexchange.com/questions/83073/is-it-possible-to-have-plain-text-and-a-link-in-the-same-cell
Today, when linking text in Google Sheets, a Tip Bubble pop'd up saying:
Cells now support multiple links You can link a portion of text or add multiple links in a cell by selecting the text and clicking the
'Insert Link' icon (or Ctrl/Cmd + K).
It is working as expected:
Enter text into the cell
Highlight a word in the cell (not in the formula editor)
Press CMD (⌘) + K
Enter a URL (Seems to prefer http://www.yourwebsitelink.com)
Apply
Highlight more text, repeat.
I have just tried the adding link by "insert link" on my google sheets. It hangs the browser tab, also the weblink keeps jumping into the actual cell, impossible to apply to pre written text in the cell. I have an updated Firefox on ubuntu 1804.
If any of you have this problem... The answer provided here by #Aibol works. I will go further and say:
Add text to cell
Copy weblink address
Ctrl - select the text to add hyperlink to
Ctrl+k, paste weblink address
Apply
You can't put it in the middle of a sentence unfortunately, if you hyperlink an entire text in a google doc you can copy and paste it over into a cell. For example, you could hyperlink "Click here" and paste click here into a sheet from a google doc
Try with =HYPERLINK("http://www.google.com","search the web") instead of =HYPERLINK("www.google.com";"search the web")
I believe you need something like this...
A B
yahoo yahoo (this will be hyperlink)
gmail gmail (this will be hyperlink)
google google (this will be hyperlink)
Use this to get above output
=HYPERLINK(CONCATENATE("http://www.",A1,".com"), A1)
Whenever you change content of Cell A, Cell B data will change
Hope this is what you needed!!!
Good Luck!!!
Update 1
Write yahoo in Cell A at first row...
In Cell B paste =HYPERLINK(CONCATENATE("http://www.",A1,".com"), A1) and see magic...
Update 2
Write jira/bug-56 in Cell A at first row...
In Cell B paste =HYPERLINK(CONCATENATE("http://www.myjirahost.com/browse/",RIGHT(A1,6)), CONCATENATE("http://www.myjirahost.com/browse/",RIGHT(A1,6))) and let me know if this is what you want...
I'm going to assume you have solved this but wanted to throw my hat in the ring for an answer. This is the line I wrote to do automatic Google search.
=HYPERLINK(CONCATENATE("https://www.google.ca/?#q=",SUBSTITUTE(A2," ","+")),"Review")
It's first you basic HYPERLINK function, within that using the CONCATENATE to bring together two things:
Google Search URL https://www.google.ca/?#q= without keywords
Then we have a cell with search terms, we use SUBSTITUTE of a blank space to be replaced with a + symbol
That's pretty much it. Hope it helps.