【发布时间】:2016-08-22 19:20:39
【问题描述】:
我目前有一个谷歌电子表格,它将创建一个 csv 文件,并在触发触发时将其保存在我的谷歌驱动器上。我想不通的是如何在创建新的 csv 文件之前删除现有的 csv 文件。当它保存新版本时,它只是制作另一个副本。我需要覆盖以前的文件(或删除旧文件然后导出/写入新版本。)
这是创建 csv 文件的脚本:
function saveAsCSV() {
// Prompts the user for the file name
var fileName = ("myCSVFile");
// Check that the file name entered wasn't empty
if (fileName.length !== 0) {
// Add the ".csv" extension to the file name
fileName = fileName + ".csv";
// Convert the range data to CSV format
var csvFile = convertRangeToCsvFile_(fileName);
// Create a file in the Docs List with the given name and the CSV data
DriveApp.createFile(fileName, csvFile);
}
else {
Browser.msgBox("Error: Please enter a CSV file name.");
}
}
如何在每次脚本触发器关闭时覆盖 csv 文件?
【问题讨论】:
-
我尝试使用该解决方案,但无法让它为我工作
标签: javascript csv google-apps-script