xml - 如何为多值 IMPORTXML 函数添加空白行?
问题描述
这是我的importxml:
=IMPORTXML(CA1,"//div[@class='1a']/div[@class='1b']/div[@class='1c']/img[@class='1d']/@src
| //div[@class='2a']/span[@class='2b']
| //div[@class='3a']/span[@class='3b']
| //div[@class='4a']/span[@class='4b']
| //div[@class='5a']/span[@class='5b']
| //div[@class='6a']/span[6]
| //div[@class='7a']/span[8]
| //a/@title")
它显示如下内容:
img src
span1
span2
span3
span4
span5
span6
a title7
现在有时,缺少跨度或 img 之一。
所以它只会制作 7 或 6 或 5 等...行,并且只显示它找到的值。
是否可以添加一个空白行,而不是消除该行?
例如:
img src
span1
BLANK ROW
span3
span4
BLANK ROW
span6
a title7
代替:
img src
span1
span3
span4
span6
a title7
解决方案
您可以做的最简单的解决方案是将单个命令IMPORTXML
分成多个IMPORTXML
命令,然后IFERROR
添加。将它组合成一个将防止您将每个不匹配的模式替换为无。
公式:
=IFERROR(CA1,"//div[@class='1a']/div[@class='1b']/div[@class='1c']/img[@class='1d']/@src]"), "BLANK ROW")
=IFERROR(CA1,"//div[@class='2a']/span[@class='2b']"), "BLANK ROW")
...
=IFERROR(CA1,"//div[@class='7a']/span[8]"), "BLANK ROW")
=IFERROR(CA1,"//a/@title"), "BLANK ROW")
样本:
=IMPORTXML("https://www.xe.com/currencytables/?from=EUR&date=2020-10-31","(//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[1] | (//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[2] | (//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[3] | (//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[4]")
输出:
=IFERROR(IMPORTXML("https://www.xe.com/currencytables/?from=EUR&date=2020-10-31","(//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[1]"), "BLANK ROW")
=IFERROR(IMPORTXML("https://www.xe.com/currencytables/?from=EUR&date=2020-10-31","(//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[2]"), "BLANK ROW")
=IFERROR(IMPORTXML("https://www.xe.com/currencytables/?from=EUR&date=2020-10-31","(//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[3]"), "BLANK ROW")
=IFERROR(IMPORTXML("https://www.xe.com/currencytables/?from=EUR&date=2020-10-31","(//h2[@class='heading__Heading1-n07sti-0 heading__Heading2-n07sti-1 iXbZUl'])[4]"), "BLANK ROW")
推荐阅读
- python - 防止用户在猜数字游戏中输入无效值
- python - 传递真实成员时出现discord.py MemberNotFound异常
- javascript - Nightmare.js 找不到 css 标签
- javascript - Rails 项目:为什么我的 javascript 文件被忽略?
- java - 每当我退出时应用程序崩溃
- html - Angular:结合几个订阅
- javascript - nodejs应用程序中的PDF到HTML
- javascript - 显示/隐藏元素时出现电话号码正则表达式验证错误
- angular - 如何使用来自 RxJS 可观察订阅调用的值
- google-apps-script - 使用 Google Apps 脚本检查播放列表中是否存在 YouTube 视频