如何使用谷歌应用脚​​本删除/覆盖CSV文件? [英] How to delete/overwrite CSV file using google apps script?

查看:112
本文介绍了如何使用谷歌应用脚​​本删除/覆盖CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的google apps脚本将一个csv文件[test.csv]导入到一个新选项卡中,操纵一些值,然后将操纵选项卡保存为csv文件[test.csv]。当它保存新版本时,它只是制作另一个副本[test(1).csv]。我希望改写以前的文件(或删除旧文件,然后导出/写入新版本)。请帮忙吗?

我使用与Docs List教程交互

解决方案

您可以执行 DocsList.find(fileName),它会给您一个具有该名称的文件列表。如果文件名是唯一的,那么你可以做 var file = DocsList.find(fileName)[0]



< hr>

如果您是Google Apps用户,则可以使用 file.clear()来删除旧文件的所有内容,然后 file.append()插入所有新内容。



< hr>

否则,您必须 file.setTrashed(true)然后 DocsList.createFile()来制作新的。


My google apps script imports a csv file [test.csv] into a new tab, manipulates some values, then saves the manipulated tab as a csv file [test.csv]. When it saves the new version, it simply makes another copy [test(1).csv]. I wish instead to overwrite the previous file (or delete the old one then export/write the new version.) Help please?

I am using reference code from the Interacting With Docs List Tutorial

解决方案

You could do DocsList.find(fileName) which gives you a list of files that have that name. If file names are unique, then you can just do var file = DocsList.find(fileName)[0].


If you are a Google Apps user, you can use file.clear() to remove all the contents of the old file, and then file.append() to insert all of the new contents.


Otherwise, you will have to file.setTrashed(true) and then DocsList.createFile() to make the new one.

这篇关于如何使用谷歌应用脚​​本删除/覆盖CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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