Can I generate a file from Google Sheets script?

Charles Randall picture Charles Randall · Aug 22, 2011 · Viewed 12.2k times · Source

I'm using Google Sheets to prototype a bunch of numerical data for something I'm doing.

Is there a way to export a subset to a text file?

Effectively, what I'm aiming to do is export a file I can include directly in the build for another project.

So is there a way to generate a text file for download?

Answer

Jan Kleinert picture Jan Kleinert · Aug 23, 2011

If you have a Google Apps account, then you can use DocsList.createFile() to create the text file and save it in your documents list.

Section 3 of this tutorial shows how to save the selected range of a spreadsheet as a file in your documents list in CSV format. It could be modified pretty easily to save in a different format.