从 Google 电子表格导出到 XML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11670338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:37:13  来源:igfitidea点击:

Exporting From Google Spreadsheet To XML

xmlgoogle-apps-scriptgoogle-sheets

提问by user1554754

I have a google docs spreadsheet and an XML file which is made on the base of this spreadsheet. What I need right now is a way to speed up exporting information to XML format. So I've turned to google scripts.

我有一个 google docs 电子表格和一个基于该电子表格制作的 XML 文件。我现在需要的是一种加速将信息导出为 XML 格式的方法。所以我转向了谷歌脚本。

I can currently retrieve certain cells from a spreadsheet and make string variables, however I need to save the resulting strings to an XML file using minimum amount of clicks.

我目前可以从电子表格中检索某些单元格并创建字符串变量,但是我需要使用最少的点击次数将结果字符串保存到 XML 文件中。

Is there any way to instantly make an xml file using google scripts and send it to download from the browser? The only way to save the result I've found is creating a plain text document in google drive folder, opening this document and manually copypasting it's content to my xml file. But it seems that this plain text documents do not understand tab-characters (\t) and I kinda need them to make a certain structure in my xml.

有什么方法可以使用谷歌脚本立即制作一个xml文件并将其发送到浏览器下载?保存我发现的结果的唯一方法是在 google drive 文件夹中创建一个纯文本文档,打开该文档并手动将其内容复制粘贴到我的 xml 文件中。但似乎这个纯文本文档不理解制表符 (\t),我有点需要它们在我的 xml 中创建某种结构。

采纳答案by Ikai Lan

Have you looked into Content Service? You would generate the XML and serve it via Content Service, set the XML mime-type, then use downloadAsFile to tell the browser to just download the file instead of displaying it.

你研究过内容服务吗?您将生成 XML 并通过内容服务提供它,设置 XML mime-type,然后使用 downloadAsFile 告诉浏览器只下载文件而不是显示它。

回答by mzimmerman

ContentService will allow you granular control over what exactly you want the XML to look like. You can also let Google create the XML Atom/RSS feed for you by publishing your sheet.

ContentService 将允许您精确控制您希望 XML 的外观。您还可以通过发布您的工作表让 Google 为您创建 XML Atom/RSS 提要。

In the Old Sheets, the Publish option allowed XML export. (No longer supported.) Here's a sample of the XML.

在旧表格中,发布选项允许导出 XML。(不再支持。)这是 XML示例