简体   繁体   English

如何在 Google 表格中的 importxml 公式中定义范围

[英]How to define range in importxml formula in Google Sheets

In my google sheet, I have URL in A1 and other data in B1, C1, D1, E1, etc... I want to use importxml formula but want to this work automatic, I mean in column B2 I try this在我的谷歌表中,我在 A1 中有 URL 和 B1、C1、D1、E1 等中的其他数据......我想使用 importxml 公式,但想自动完成这项工作,我的意思是在 B2 列中我试试这个

=ARRAYFORMULA( IMPORTXML($A1&$B1:$CZ1, "//suggestion/@data"))  

so its do the rest of the job automatic I mean fetch data for A1and B1 in B2 and do A1 and C1 in C2 and A1 and D1 in D2, is it possible?所以它自动完成作业的 rest 我的意思是在 B2 中获取 A1 和 B1 的数据并在 C2 中执行 A1 和 C1 以及在 D2 中执行 A1 和 D1,这可能吗? I mean now I have to do manually enter formula in every column.我的意思是现在我必须在每一列中手动输入公式。 hope you understand what I mean.希望你明白我的意思。

Column A   | Column B    | Column C
=================================
site.com   | Name 1      | Name 2
           |             |  
           |             |  
           |             |  

Column A   | Column B    | Column C
=================================
site.com   | Name 1      | Name 2
           | =ARRAYFORMULA( IMPORTXML($A1&$B1:$CZ1, "//name/@data"))  
           |             |  
           |             |  

IMPORTXML is not supported in ARRAYFORMULA as you expect it.如您所料, ARRAYFORMULA不支持IMPORTXML your options are:您的选择是:

  • paste in B2 and drag the formula to the right粘贴到B2并将公式拖到右侧

    =IMPORTXML($A1&B1, "//suggestion/@data")

  • paste in B2 the hardcoded formula for all columns:B2中粘贴所有列的硬编码公式:

     ={IMPORTXML(A1&B1, "//suggestion/@data"), IMPORTXML(A1&C1, "//suggestion/@data"), IMPORTXML(A1&D1, "//suggestion/@data")}

    0

or scripted solution:或脚本解决方案:

function onOpen() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var length = sheet.getRange("B2:2").getValues().filter(String).length;
    sheet.getRange("C3:3").clearContent();
    sheet.getRange("C3:3" + length).setFormula(sheet.getRange("B3").getFormula());
    sheet.getRange("C4:1000").clearContent();
    }

where cell B2 is:其中单元格B2是:

=ARRAYFORMULA(A1&B1:D1)

and cell B3 is:单元格B3是:

=ARRAYFORMULA(IFERROR(IMPORTXML(B2:2, "//suggestion/@data")))

0

unfortunately I run into an error where I have 100 rows in the sheet and Google says I have too many API requests using this ImportXML function:(不幸的是,我遇到了一个错误,我在工作表中有 100 行,谷歌说我有太多的 API 请求使用这个 ImportXML function:(

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

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