I’m trying to have a clickable link which results in a google sheets document being downloaded.
Code as follows:
from anvil import *
import anvil.server
import google.auth, google.drive, google.mail
from google.drive import app_files
class form1 (form1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
def link_1_click (self, **event_args):
self.link_1.url = app_files.file1.get_url()
Any advice how to use the url property in this context?
Ah, this is really close to working! The url property tells the link where to go when it is clicked, so you need to set it before the link is clicked. Then you don’t need the link_1_click event handler.
I think you probably want something like this:
from anvil import *
import anvil.server
import google.auth, google.drive, google.mail
from google.drive import app_files
class form1 (form1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
self.link_1.url = app_files.file1.get_url()
Ah, yes, sorry. You can get URLs for real files in Google Drive, but not for Google Sheets. This is because they’re not real files, so they can’t be downloaded through Anvil in the way that you can, say, export them to Excel through the Google Sheets interface.
If you want to link people to a Google Sheet, the best bet is to use the standard Google Sheets interface to do it. You’ll want to set the file to be read-only for anyone with the link, then paste that URL into the url property of the link on your Anvil form.