如何将importXML函数与Google云端硬盘中的文件一起使用? [英] How to use importXML function with a file from Google Drive?

查看:117
本文介绍了如何将importXML函数与Google云端硬盘中的文件一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在云端硬盘中存储了一个.xml文件,并希望使用importXML()提取信息.但是,当它是来自Drive的可共享链接时,它将不起作用.

I have an .xml file stored in Drive and would like to extract information using importXML(). However, it doesn't work when it's a sharable link is from Drive.

推荐答案

我认为有2种模式.

在这种情况下,必须将电子表格上使用的所有XML文件共享为ANYONE_WITH_LINK和VIEW.共享文件的URL为https://drive.google.com/uc?id=### file id ###&export=download.因此公式如下.

In this case, all XML files which are used on Spreadsheet have to be shared as ANYONE_WITH_LINK and VIEW. The URL of the shared file is https://drive.google.com/uc?id=### file id ###&export=download. So the formula is as follows.

=importXML("https://drive.google.com/uc?id=### file id ###&export=download","### XPath query ###")

2.使用Web Apps间接读取XML文件

在这种情况下,不需要共享电子表格上使用的XML文件,因为已部署了Web Apps.但是在这种情况下使用GAS.此方法的安装如下.

2. Read indirectly XML files using Web Apps

In this case, the XML files which are used on Spreadsheet are not required to share, because Web Apps is deployed. But GAS is used for this case. The install of this method is as follows.

function doGet(e) {
  var xml = DriveApp.getFileById(e.parameters.id).getBlob().getDataAsString();
  return ContentService.createTextOutput(xml).setMimeType(ContentService.MimeType.XML);
}

2. 部署Web应用

  • 在脚本编辑器上
    • 文件
    • ->管理版本
    • ->保存新版本
    • 发布
    • ->部署为Web应用
    • ->在执行应用程序为"下,选择您的帐户"
    • ->在谁可以访问该应用程序"下,选择任何人,甚至是匿名的"
    • ->单击部署"
    • ->复制当前Web应用程序URL"
    • ->单击确定"
    • 2. Deploy Web Apps

      • On the Script Editor
        • File
        • -> Manage Versions
        • -> Save New Version
        • Publish
        • -> Deploy as Web App
        • -> At Execute the app as, select "your account"
        • -> At Who has access to the app, select "Anyone, even anonymous"
        • -> Click "Deploy"
        • -> Copy "Current web app URL"
        • -> Click "OK"
        • 复制的当前Web应用程序URL 用于importXML().因此,电子表格上的公式如下.

          The copied Current web app URL is used for importXML(). So the formula on Spreadsheet is as follows.

          =importXML("https://script.google.com/macros/s/#####/exec?id=### file id ###","### XPath query ###")
          

          如果这些对您没有用,对不起.

          If these were not useful for you, I'm sorry.

          这篇关于如何将importXML函数与Google云端硬盘中的文件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆