简体   繁体   English

Google Sheet importxml 从 xml 文件创建表

[英]Google Sheet importxml create table from xml file

Trying to use importxml in google-sheets.尝试在 google-sheets 中使用 importxml。 My XML file is something like this:我的 XML 文件是这样的:

<file>
<file_name>file1</file_name>
<file_id>407897</file_id>
<disk_id>180622</disk_id>
</file>

There are tons of files in this xml ~5k.这个 xml ~5k 中有大量文件。 I'm trying to have a table in a google-sheet like this below:我正在尝试在下面的 google-sheet 中有一个表格:

col 1 | col 2 | col 3
file1 | 001   | 001
file2 | 002   | 002

Now sometimes file doesn't have a disk id so it would be:现在有时文件没有磁盘ID,所以它会是:

  <files>
    <file>
    <file_name>file1</file_name>
    <file_id>1</file_id>
    <disk_id>1</disk_id>
    </file>
    <file>
    <file_name>file2</file_name>
    <file_id>2</file_id>
    </file>
    <file>
    <file_name>file3</file_name>
    <file_id>3</file_id>
    <disk_id>1</disk_id>
    </file>
<files>

Table I want to create would something like this:我要创建的表是这样的:

col 1 | col 2 | col 3
file1 | 001   | 001
file2 | 002   | 
file2 | 002   | 001

I tried using:我尝试使用:

=importxml("url","//file_name | //file_id | //disk_id")

This gave me something like this (single column):这给了我这样的东西(单列):

file1
001
001
file2
002
file3
003
001

and adding transpose it gave something like this:并添加转置它给出了这样的结果:

=transpose(importxml("url","//file_name | //file_id | //disk_id"))

file1 001 001 file2 002 file3 003 001

Is there any way to get this using importxml in google-sheets?有没有办法在谷歌表格中使用 importxml 来获得这个?

You are very close to reaching your goal.你非常接近实现你的目标。 You only need to modify the XPath in the IMPORTXML formula to read rows instead of attributes.只需修改IMPORTXML公式中的XPath即可读取行而不是属性。 Based on your example XML, you want something like this:根据您的示例 XML,您想要这样的东西:

=IMPORTXML("{XML URL}","/FILES//FILE")

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

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