如何使用Google Apps脚本下载创建的csv文件?

问题描述:

我在Google Apps Script中创建了一个文件,如下所示:

I've created a file in Google Apps Script as follows

DocsList.createFile(
   "test.csv", 
   "Row1Col1,Row1Col2 \r\n Row2Col1,RowCol2 \r\n Row3Col1,Row3Col2");

如何以编程方式下载(例如,通过弹出式下载对话框)?

How to download it programmatically (via a popup Download dialog for example) ?

请尝试使用 ContentService ,您可以触发下载,甚至通过 TextOutput.downloadAsFile方法设置文件名。您还可以设置返回数据的内容MIME类型,但仅限于预定义的枚举常量。请参阅其示例

Try using ContentService, you can trigger a download and even set the file name via the TextOutput.downloadAsFile method. You can also set the content mime type of the returned data, though only to a predefined enum constant. See their examples.