Google sheet cell value to html page - google-apps-script

I'm doing a little project and I would like to display the top player (Cell A2) of a ranking (sheet: ranking) in an HTML page. My google sheet is shared with everyone.
I found similar questions with several answers. But it seems that each answer is a part of the cake. I can't manage to take everything and simply apply it to my project.
I'm trying to :
Use the Code.gs file of my google spreadsheet project to return the cell value
Call the cell value in my index.html file using the thing
Display the cell value in a paragraph (p)
What is the easiest way to do that?
Thank you for helping me to find my full cake :)

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.

Pull/parse info from HTML into Google Sheet using XPath

I'm currently trying to make a first script in Google Sheets to automate a small task in the workplace.
The plan is to have the sheet make a call to a specific URL by combining the page url and a tracking number, e.g. https://t.17track.net/en#nums=NUM123ABC
Then pull relevant data from a specific div relevant to the tracking information box in the result, and fire it back into a cell or cells in Google Sheets.
My question is, can this be done by using XPath on an HTML page such as the one above?
Thanks for your time!

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

Unable to extract link text from tooltip in Google Spreadsheet

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.

After using importRange to get Hyperlinked cells, how do you get the value of the URL?

I was trying to help someone solve a problem the other day and I came across an interesting issue I couldn't solve.
Imagine two sheets. One containing HYPERLINKS created by HYPERLINK function in Google Sheets, such as this sheet.
Source Sheet
Then you have another sheet that uses importRange to import these URL's, like this sheet.
import Sheet
The URLs import correctly, with correct link and link text.
But no matter what I tried, in the import sheet, I couldn't extract the link value.
I tried to do this via formulas and via scripting. I'm guessing the URL must be some sort of object but I cannot seem to read or split it. Whatever efforts I've tried have always returned the link text, EG Google, Yahoo and not the URL itself.
There is no way to getting the hyperlink value from the cell. getValues, getDisplayValues, even getDataSourceUrl do not return the hyperlink value, only the display value as a string. And because this is from an IMPORTRANGE getFormulas will only return an empty array.
If you want you can put in a feature request at:
https://code.google.com/p/google-apps-script-issues/issues/list