使用脚本读取文件 [英] Read a file with script

查看:48
本文介绍了使用脚本读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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.

推荐答案

根据Apps脚本上的Google参考,您可以使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆