Script to get a GooglePhoto using filename stored in GoogleSheets - google-apps-script

I have a Googlesheets that has in one of its columns the filename (as "filename.jpg") of pictures stored in GooglePhotos (and/or Google Drive). I would like to have a script that would show me the selected picture when I click on a given cell of that particular column.
I'm quite familiar with Googlesheets Scripts and have looked at Google Photos API but don't know where to start.
Has anyone developed something like this and is willing to share? Any hints will be very much appreciated.
Many thanks in advance

I have a similar solution. You have to start from Browser API and this existing repo https://github.com/gsuitedevs/apps-script-samples/tree/master/docs/dialog2sidebar
But before that you have to realize the next flow:
Get a string
Try to search the file with this string
Return the file or undefined

Related

Google Sheets script: swap URLs

I have a Google Sheet that links out to several areas in another app. I was informed that the app is going to have its URL changed, and I was wondering if there's a way to script something to easily update the links in my sheet.
While the domain of the URL will be changing, the trailing information will remain the same. Here's an example:
Current URL structure
currenturl.app.com/folder/item.html
New URL structure
newurl.app.com/folder/item.html
Is there a way that I can just search my file for currenturl.app.com and change that to newurl.app.com, and leave the /folder/item.html in place using a Google script?
Any help would be greatly appreciated, manually updating each link is going to take forever!
Thank you :)
You don't need Apps Script for this. Just use Find & Replace

Why am I receiving "Could not fetch URL" error on Google Sheets Import XML?

New here, and still trying to wrap my mind around this importXML tool in Google Sheets. Seem to be able to get it to work on certain websites, but when data is deeply embedded in code, I struggle.
Goal: To pull in weight of items listed on bricklink.com to a Google Sheet.
Link to my Google Sheet: https://docs.google.com/spreadsheets/d/1_vhCkEJXofxMj1Cg117RgPJSFTqPF0ijo_f60mDR6MU/edit?usp=sharing
When I copy the xpath from the source code on the site, I'm given this value: //*[#id="item-weight-info"].
The existing fomula I have is: =IMPORTXML(D2,"//*[#id='item-weight-info']")
D2 Contains the web address where it concatenates the website + the item number.
Error I'm receiving is: "Could not fetch url: https://www.bricklink.com/v2/catalog/catalogitem.page?S=21318"
I did come across a potential JSON solution, set up a JSON function in the sheet, but have never written a script before. Tried to copy a script, and tweak as needed, but still no luck.
Is there an easier way to do this that I'm overlooking?
Any guidance or suggestions would be greatly appreciated. Thank you for your time!

Custom formula returning #NAME when Google Sheets is published to web

I'm not much of a programmer, but I managed to write a Google Sheets script that sorts an array, filters out specified values, and returns the new array. It works great.
However, when I publish the output page to the web, the link will only successfully show the output if I have the back end sheet open. As soon as I close it, the publish page turns up #NAME.
Presumably there is some restriction as to the availability of custom scripts. I assumed the output would just grab the text, but I suppose it's trying to run it and can't without someone being logged in?
Anyways - is there some way around this?
Thanks
Edit: Did a little further reading and found out that this might be a situation where "script as web app" might be the requirement. As a novice, this is a little over my head and I'd appreciate any advice.
I also tested to make sure IMPORTRANGE() as a source for this data wasn't the issue, and though it may cause other problems once I get the #name issue resolved, it does not appear to be at fault here specifically since the same thing happens with local data.
Yes, as you've stated, script as web app might be the requirement. You may also want to check this documentation regarding Custom Functions in Google Sheets. Just be noted that a script can be published as a web app if it meets these requirements:
It contains a doGet(e) or doPost(e) function.
The function returns an HTML service HtmlOutput object or a Content service TextOutput object.
Hope this helps!

Uploading an XLSX converting and replacing a current spreadsheet

Just a general question, I would like to create a user upload form that would convert an .xlsx to the corresponding Google Sheets version and then replace a currently existing sheet on my drive. The main question and aspect that I'm not sure is achievable is replacing a current google sheet. Is a project like this even achievable in a reasonable manner? The reason I want to replace it is because the KeyID for that sheet is used in a couple other app scripts for a website. Thanks for the suggestions and advice.
Yes, this is possible. About being "reasonable", well... I think it is, it's not a single line script, but this is not the most simple task either.
But from what I understood from your use-case (other app script for a website), I think it's better if you enhance your other scripts to either look for the newest sheet on a given folder or fetch the ID from somewhere that you can update from the "form upload" script. Also, by doing this, you'll avoid getting inconsistent data in the middle of an update.

Use a Google Docs Spreadsheet as a datasource for a dynamic Google Sites webpage

I have a Google Form that feeds a Google Docs Spreadsheet. I'd like to--in turn--have that Google Docs Spreadsheet feed a webpage.
In plainer English, babysitters fill out the form to sign up to be in our community's Babysitter Directory. The spreadsheet houses all of the data. I'd like to code a webpage to pull selected bits of the data for the online directory.
I've tried doing a separate sheet in the spreadsheet, using a QUERY to select the columns that I want to include (and the order in which I want to include them), publishing that sheet to the web, then embedding that sheet into the webpage in an iFrame. And that works.
But even with the QUERY, there are SO many columns that users need to scroll WAY over to the right to see all the data for each babysitter. It's unwieldy.
What would be way better would be if I could break the data for each entry over multiple lines and do some nice formatting for a directory, rather than just a linear spreadsheet. So that, essentially, each babysitter's "entry" in the directory is more than 1 line long. Does that make sense?
If I was working in Office, I would know exactly what to do: use the Excel spreadsheet as the datasource for a Word Mail Merge and I would put move the fields around on the page to make it all look good.
And, to be sure, if I can do this in a Google Doc, then embed the Doc into the webpage, that's fine, too. But I would think there's some way I can do it directly in the Google Site?
Can I?
If anybody has even just a reference page for me to take a look at, I'd appreciate it.
Thanks!
Are you trying to do this in Google Sites? If so, you can embed the entire spreadsheet on the page, but if you only want certain columns, you can try inserting an Apps Script widget on the page.
You need to know how to write a Google Apps Script that will run JS functions and render HTML, here is a tutorial
To create the Script that can run on your page, go to:
More > Manage site > Apps Script > Add new script
Here's also a link to how to interact with Spreadsheet data.
What you want to do is more or less a database interface that uses a spreadsheet as 'data holder', depending on your programming skills it can be quite easy or very hard...
Here is an example of such a webapp, its has probably too many fields and features but the general idea is the same (a quick search tool and a window to show results).
It that what you had in mind ?
If so I can share the code to help you to get started but if you are not familiar with javascript it will probably need too much effort to get through.