google-sheets - 从列标题返回列值
问题描述
在回答我的问题时(我将留下下面的链接),使用的公式和结果如下:
https://stackoverflow.com/a/65451225/11462274
=IMPORTXML("https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr")
列可以更改位置,但每个列的标题都遵循新列的位置,所以我怎么能要求一个公式来搜索列所在的title X
位置并从中找到值⚽ Matches
在这种情况下,值将是: 通过 VLOOKUP 解释:
=ARRAYFORMULA(IFERROR(VLOOKUP(UNIQUE(B2:B),B1:F,3,FALSE)))
问题在于带有VLOOKUP
的列title X
可能并不总是在column D
并且⚽ Matches
可能并不总是在column B
解决方案
利用:
=ARRAYFORMULA(IFERROR(VLOOKUP(UNIQUE(B2:B),
{FLATTEN(QUERY(TO_TEXT(TRANSPOSE(IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr"))),
"where Col1 contains 'Matches'", 0)), IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr")}, 5, 0)))
例如。部分是:
=INDEX(FLATTEN(QUERY(TO_TEXT(TRANSPOSE(IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr"))),
"where Col1 contains 'Matches'", 0))
和完整的公式:
=ARRAYFORMULA(IFERROR(VLOOKUP(UNIQUE(B2:B),
{FLATTEN(QUERY(TO_TEXT(TRANSPOSE(IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr"))),
"where Col1 contains 'Matches'", 0)), IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr")},
MATCH("X", INDEX(IMPORTXML(
"https://www.soccerstats247.com/predictions/brazil/serie-a/",
"//table[@id='soccerContentPlaceHolder_gv1X2Predictions']/tbody/tr"), 1), 0)+1, 0)))
推荐阅读
- amazon-redshift - 对 Redshift 的查询中的“nolock”子字符串是怎么回事?
- python - LinkExtractor for xpath-ed response TypeError: unhashable type: 'SelectorList'
- c# - AES GCM NoPadding 解密逻辑
- ckeditor - 获取图片 url ckfinder
- amazon-web-services - AWS OpenSearch 为用户提供只读访问控制面板
- r - 为什么 sum() 在应用于数据帧时不会产生与加法相同的值?
- math - APL 中的阶乘数字和(Project Euler 20)
- python - 为什么当密码在 python 中作为字节对象传递时,密码不能在 s3 中打开我的 zip 文件?
- powershell - 从命令行/ PowerShell 合并 CSV 文件中的两列
- flutter - 由于无法识别 ArchLinux 中的 gtk3 安装,Flutter Linux 应用程序构建失败