简体   繁体   English

如何在ImportXML的URL中包含Google表格单元格引用

[英]How to include a Google Sheets cell reference in URL for ImportXML

I have this ImportXML formula : 我有这个ImportXML公式:

=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date=2018-04-01"; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

I want the value of the parameter "&date=" to be replaced by a cell reference (B1). 我希望将参数“&date =“的值替换为单元格引用(B1)。

I've tried this : 我已经试过了:

=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date="&B1"; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

But Google Sheet gave me an error. 但是Google表格给我一个错误。 Any insights? 有什么见解吗?

I think that when "https://www.x-rates.com/historical/?from=USD&amount=1&date="&B1 is used, 2018-04-01 of "B1" may be converted to the serial number. 我认为,当使用"https://www.x-rates.com/historical/?from=USD&amount=1&date="&B1 )时,“ B1”的2018-04-01可能会转换为序列号。 And please remove " of &B1"; 并且请删除"&B1"; . So how about these modifications? 那么这些修改呢? I think that there are several answers for your situation. 我认为您的情况有几个答案。 So please think of this as one of them. 因此,请将此视为其中之一。

=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date=" & TO_TEXT(B1) ; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

or 要么

=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date=" & TEXT(B1,"yyyy-MM-dd") ; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

References : 参考文献:

If this was not what you want, I'm sorry. 如果这不是您想要的,对不起。

Edit : 编辑:

In your question, =IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date=2018-04-01"; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']") returns the same values like 1.232118 1.232118 . 在您的问题中, =IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date=2018-04-01"; "//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")返回相同的值,例如1.232118 1.232118 So this is not due to date=" & TO_TEXT(B1) ; . It is considered that this is due to the xpath. I couldn't notice that this is your another issue from your question. I'm really sorry. So I updated the xpath. 因此,这不是由于date=" & TO_TEXT(B1) ; 。我们认为这是由于xpath引起的。我没有注意到这是您提出的问题中的另一个问题。非常抱歉,所以我更新了xpath。

=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date= & TO_TEXT(B1) , "//tr[1]//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

Note : 注意 :

  • There are 2 <td class='rtRates'><a href='http://www.x-rates.com/graph/?from=EUR&amp;to=USD'> in the URL. URL中有2个<td class='rtRates'><a href='http://www.x-rates.com/graph/?from=EUR&amp;to=USD'> So 1st one is retrieved in this modification. 因此,在此修改中检索到第一个。 When you want to 2nd one please use =IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date= & TO_TEXT(B1) , "//tr[position()>1]//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']") 当您想第二个时,请使用=IMPORTXML("https://www.x-rates.com/historical/?from=USD&amount=1&date= & TO_TEXT(B1) , "//tr[position()>1]//a[@href='http://www.x-rates.com/graph/?from=EUR&to=USD']")

If I couldn't notice something yet and I misunderstand your question, I'm sorry. 如果我还没注意到任何事情,但我误解了您的问题,对不起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM