Read a file with script

爱⌒轻易说出口 提交于 2021-01-28 08:14:52

问题


I want to get the content of a file (as string) with google script. It's a txt or html file which I want to edit as string after. The file is stored on Google Drive and I know the ID.

What I know that you can access the file with:

var Template = DriveApp.getFileById('18DEuu91FJ4rhTYd-xrlNpP2U9jfyheEI');

But I can nothing find how to read the content of this file like "file_get_contents" in PHP.


回答1:


According to Googles Reference on the Apps Script you can use the getAs() method to return the file contents. I haven't tested this myself, but you could try something like:

var Template = DriveApp.getFileById('18DEuu91FJ4rhTYd-xrlNpP2U9jfyheEI');
var contents = Template.getAs('text/plain');


来源:https://stackoverflow.com/questions/47462391/read-a-file-with-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!