I'm trying to extract rate data from below URL by using Google Spreadsheets:
used importXML() function with following XPath sting:
=IMPORTXML("https://www.superrichthailand.com/#!/en/exchange","//span[#class=""ng-binding""]")
Which, it should return every entry in the pages all the rate but return empty.
Google Sheets IMPORTXML can't access dynamically generated data, only the source code in the file referred by the URL.
Related
I try to import historical data (CSV) for APPLE. I use ImportData function in Google Sheet with
https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true
but the result is "#N/A".
I want to get the CSV because there is 3 decimals. And only 2, on the website.
=IMPORTXML("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true")
There is a script after to obtain the file : AAPL.csv .
Can you help me ?
Unfortunately, in the case of the URL, it seems that IMPORTDATA and IMPORTXML cannot be used. But, fortunately, I confirmed that UrlFetchApp of Google Apps Script can be retrieved the CSV data. So, in this answer, I would like to propose to use Google Apps Script for achieving your goal.
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet, and please put =SAMPLE("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true") to a cell. This script is used as the custom function. By this, the CSV data can be retrieved in the cells.
const SAMPLE = url => Utilities.parseCsv(UrlFetchApp.fetch(url).getContentText());
Result:
When above script is used, the following result is obtained.
References:
Custom Functions in Google Sheets
Class UrlFetchApp
Utilities.parseCsv()
I am working on a script that is standalone. It collects its baseline data from a google sheet bound to a form. In the form submission, excel documents are uploaded. While I can access the link for the excel document(google downloads the excel into your drive upon submission and inserts the drive link into the google response sheet), I am having difficulty looking into and extracting anything (exact cell values, ranges, indexes, etc) from the excel doc.
I have tried using various functions from the sheets and spreadsheets classes and continue to get errors. Some suggestions I've found say the excel document needs to be converted into a google sheet before the app script can access it, or that app script won't allow you to work with such a document if it is not bound to your script (since that allows you to activate it)(I can't bind the excel doc because it changes upon every new submission of the form).
Has anyone ever compiled a similar code and figured out how to access an unbound, non-google doc?
Let me know if you need error codes or script snippets. I just wasn't sure if this was a syntax problem or a google suite trick spot that needed extra code that I probably haven't found cause I'm new to this platform.
From the question
Has anyone ever compiled a similar code and figured out how to access an unbound, non-google doc?
Scripts in Google Apps Script aren't "compiled" by the script writer in the sense that it's done when developing something in other platforms.
To get data from a file hosted in Google Drive, first the script should get that file by using the Drive Service (Class DriveApp) or the Drive Advanced Service.
The next part depends pretty much on the Excel file format. If it's an xlsx file, then usually the most convenient is to convert the file into an Google spreadsheet as this will make possible to use the Spreadsheet Service (Class SpreadsheetApp) to read the data from it.
If you don't want to convert it to a Google spreadsheet file, or it can't be converted the the "basic" means because it's using an incompatible format (like a xls file format), then you will need to use an library or an external service to parse the Excel file content.
function getalldataonsheet() {
const ss=SpreadsheetApp.openById('ssid');//you provide id
const sh=ss.getSheetByName('sheetname');//you provide sheet namme
const rg=sh.getDataRange();
const vs=rg.getValues();//2d array
return vs;//this return 2d array
}
There are restrictions for passing parameters in client to server communication
I am creating a spreadsheet portfolio. I came across some limitation, e. g. that I can not automate the process of importing the data from a website for different stocks. This is since the Index for the stock information on the website is often different from another stock. However there is the pattern that it is the next Index from a defined string e. g. "Branche". This made me wonder if I can automate the process with the Google Apps Script.
I wrote down the steps at first in Google Sheets. Then I formulated the steps in the Google Apps Script. Now I am stuck.
Step 1
=IMPORTXML("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=9386126";"//tr/td[#class='simple-table__cell']")
Step 2
=IMPORTXML(CONCATENATE("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=";"9386126");"//tr/td[#class='simple-table__cell']")
Step 3
=INDEX(IMPORTXML(CONCATENATE("https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION=";"9386126");"//tr/td[#class='simple-table__cell']");62;1)
Step 4 final product - just an idea not working yet
function import_branche() {
var url1 = "https://www.comdirect.de/inf/aktien/detail/uebersicht.html?ID_NOTATION="
var ulr2
var ticker = "//tr/td[#class='simple-table__cell']"
Index = find the INDEX with the String == "Branche"
return Index(IMPORTXML(CONCATENATE(url1;url2); ticker);(Index+1);1)
}
Ideally, I would like to have a function where I only need insert the link of the website and get the result. Here is the index for the information automatically found.
Google Apps Script can't execute Google Sheets spreadsheet functions like IMPORTXML, so you have two basic alternatives
Use Google Apps Script to get the result of a IMPORTXML formula from the spreadsheet, then use JavaScript to do the rest of the job
Do the job completely using Google Apps Script and JavaScript
Related
Google docs ImportXML called from script
(javascript / google scripts) How to get the title of a page encoded with iso-8859-1 so that the title will display correctly in my utf-8 website?
I have two Google Sheets (sheetA and sheetB) and I'd like to know if it is possible to use the following hyperlink on a cell in sheetA to capture "Ford" in a cell in sheetB.
=HYPERLINK("https://docs.google.com/spreadsheets/d/1KmT653Ec0xREBw7AQlhG2jLWuPdVSqnp0nuLtgwrnI0/edit#gid=990300781?make=Ford","Ford")
If it isn't possible using the GET Method to append the hyperlink in sheetA, do you know of another way to pass info via a hyperlink to a cell in a google sheets?
Thanks for your insight and assistance.
The hyperlink formula only inserts a hyperlink to be clicked by a user, it doesn't send any HTTP requests.
On the other hand, importXML, importHTML, importFeed, and importData functions do fetch certain kinds of data (XML/HTML, HTML tables/lists, RSS/Atom, and CSV, respectively).
But apparently, your goal is to fetch data from another Google spreadsheet. The primary tool for that is importrange, which does not perform GET requests but directly gets the requested data from another spreadsheet with a given key or URL.
I need to generate/display an HTML page (or iframe or how-ever it could be done on demand from an apps script) from a Google sheet using Apps Scripts. It looks like there's an htmlForms service for Docs, but I can't find the equivalent for sheets.
My goal is to provide a menu item that can parse my data (already done) then call up another page where knockOutJs will be used to transfer the generated JSON into an html preview. Right now my script generates the JSON and if I could use something like
I'm using HtmlService.createHtmlOutputFromFile() to generate the HTML but FormApp.getUi() isn't valid in this context and neither is
You must get a reference to the current SpreadSheet (not the "ActiveSheet", but the entire SpreadSheet object) then call show() passing in your object from createHtmlOutputFromFile() or similar method.
var htmlRes HtmlService.createHtmlOutputFromFile('YourProjectHtmlFile');
SpreadsheetApp.getActiveSpreadsheet().show(htmlRes);