简体   繁体   English

Google Spreadsheets ImportXML分为2列

[英]Google Spreadsheets ImportXML into 2 columns

I have an xml document that looks like this: 我有一个看起来像这样的xml文件:

<Time>
<ID>22653948</ID>
<Job>
<ID>J000010</ID>
<Name>NEP0001_Evesham</Name>
</Job>
<Task>
<ID>12379652</ID>
<Name>Assemble</Name>
</Task>
<Staff>
<ID>68684</ID>
<Name>Ruiardh Robinson</Name>
</Staff>
<Date>2012-10-29T00:00:00</Date>
<Minutes>180</Minutes>
<Note/>
<Billable>true</Billable>
</Time>

The document contains multiple <Time> entries and what I'm trying to do is import all the <Date> and <Minutes> fields for each task, only where the date contains the string "2014". 该文档包含多个<Time>条目,而我想做的是导入每个任务的所有<Date><Minutes>字段,仅在日期包含字符串“ 2014”的情况下。 I can import all the dates fields from 2014 using: 我可以使用以下命令导入2014年的所有日期字段:

=QUERY(ImportXML('Time Data'!F2, "//Time/Date"), "SELECT * WHERE Col1 contains '2014-04'")

But I can't get the corresponding minutes field for the same entry, I know you can do multiple xpath queries using the | 但是我无法获得相同条目的相应分钟数字段,我知道您可以使用|来执行多个xpath查询| operator and I tried the following but it doesn't work as it just returns the first date field from the first entry for some reason. 运算符,我尝试了以下操作,但由于某种原因它仅从第一个条目返回了第一个日期字段,因此它不起作用。

=QUERY(ImportXML('Time Data'!F2, "//Time/Date | //Time/Minutes"), "SELECT * WHERE Col1 contains '2014-04'")

Does anyone know how I can import both columns only where the date contains "2014"? 有谁知道我如何仅在日期包含“ 2014”的地方导入两个列?

You could use: 您可以使用:

//Time/*[self::Date or self::Minutes]

however the way google reads the XML, this will populate across rows and not columns, so if you have the query in A1 the result will be 但是google读取XML的方式,它将跨行而不是列填充,因此,如果您在A1中进行查询,则结果将是

   A                    B                  C     ...
1 2012-10-29T00:00:00
2 180

So if you want this to be in columns you could just add a 2nd ImportXML query in B1 that uses //Time/Minutes 因此,如果您希望将其放在列中,则可以在B1中使用//Time/Minutes添加第二个ImportXML查询

Personaly however I'd just import the whole XML in another sheet and then query that. 但是,就我个人而言,我只是将整个XML导入另一个工作表中,然后进行查询。

Btw you could also use //Time[starts-with(Date, '2014')] instead of wrapping the ImportXML in QUERY 顺便说一句,您也可以使用//Time[starts-with(Date, '2014')]而不是将ImportXML包装在QUERY中

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

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