On Google Spreadsheet how can you query 'GoogleFinance' for a past exchange rate?

前端 未结 7 773
情话喂你
情话喂你 2020-12-24 00:33

I\'d like to know if it is possible to query a past exchange rate on Google Spreadsheet.

For example; using formula =GoogleFinance(\"CURRENCY:USDEUR\")

7条回答
  •  悲哀的现实
    2020-12-24 01:17

    For bigger spreadsheets, Google Sheets limitations usually will show randomly the following error:

    Error Function INDEX parameter 2 value is 2. Valid values are between 0 and 1 inclusive.

    Even modifying Index() and GoogleFinance() following the expected parameters GOOGLEFINANCE(ticker, [attribute], [start_date], [end_date|num_days], [interval]) the error will continue. A workaround is to copy smaller parts into new spreadsheets but often it will fail.

    As an alternative, I used ImportXML as web scraper for x-rates historical currency exchange data.

    =index(IMPORTXML("https://www.x-rates.com/historical/?from="&N2&"&amount="&K2&"&date="&YEAR(B2)&"-"&TEXT(B2,"mm")&"-"&TEXT(B2,"dd")&"","//td[@class='rtRates']"),1)
    

    I'm assuming column B are dates, K is for amounts and N for currencies.

    Randomly it also will fail for a 2000+ rows spreadsheet but overall for my requirement, it worked too much better than GoogleFinance()

    ImportXML examples

    The ImportXML Guide for Google Docs from beginner to advanced

提交回复
热议问题