使用脚本读取文件 [英] Read a file with script
问题描述
我想使用Google脚本获取文件的内容(作为字符串).这是一个txt或html文件,之后我想将其编辑为字符串.该文件存储在Google云端硬盘中,我知道ID.
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模板= DriveApp.getFileById('18DEuu91FJ4rhTYd-xrlNpP2U9jfyheEI');
但是我什么也找不到如何读取该文件的内容,例如PHP中的"file_get_contents".
But I can nothing find how to read the content of this file like "file_get_contents" in PHP.
推荐答案
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');
这篇关于使用脚本读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!