以下代碼用于在執行分析腳本后重新初始化檔案。目標是擦除已經為新請求手動填寫的單元格。
錯誤是在分析程序結束時獲得的,我無法追查問題的根源。
// Before you run the script, please enable Drive API at Advanced Google services.
function resetFile() {//restore previous version of the file
var revisionId = "1"; // Please set the revision ID you want to revert.
var googleDocsFileId = SpreadsheetApp.getActiveSpreadsheet().getId(); // Please set the Google Docs file ID.
var endpoints = Drive.Revisions.get(googleDocsFileId, revisionId).exportLinks;
var keys = Object.keys(endpoints);
for (var i = 0; i < keys.length; i ) {
if (keys[i].indexOf("application/vnd.openxmlformats-officedocument") > -1) {
var endpoint = endpoints[keys[i]] "&access_token=" ScriptApp.getOAuthToken();
var mediaData = UrlFetchApp.fetch(endpoint).getBlob();
Logger.log(mediaData.getBytes().length)
Drive.Files.update({}, googleDocsFileId, mediaData);
break;
}
}
}
function resetSource(){//pas nécessaire
var file= SpreadsheetApp.getActiveSpreadsheet().getRangeByName("FileID").getValue();
var fileID = DriveApp.getFileById(file);
fileID.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.EDIT);
}
2022-01-14 更新

uj5u.com熱心網友回復:
根據您的錯誤訊息,在您的情況下,如何檢索第一個現有修訂版本?當這反映在您的腳本中時,它變成如下。
從:
var revisionId = "1";
var googleDocsFileId = SpreadsheetApp.getActiveSpreadsheet().getId();
到:
var googleDocsFileId = SpreadsheetApp.getActiveSpreadsheet().getId();
var list = Drive.Revisions.list(googleDocsFileId, { fields: "items(id)" }).items;
if (list.length == 0) throw new Error("No revisions were found.");
var revisionId = list[0].id;
參考:
- 修訂:串列
uj5u.com熱心網友回復:
// 在運行腳本之前,請在 Google 高級服務中啟用 Drive API。
function resetFile() {
//restore previous version of the file var revisionId = "1"; // Please set the revision ID you want to revert.
var googleDocsFileId = SpreadsheetApp.getActiveSpreadsheet().getId();
// Please set the Google Docs file ID.
var endpoints = Drive.Revisions.get(googleDocsFileId, revisionId).exportLinks;
var keys = Object.keys(endpoints);
for (var i = 0; i < keys.length; i ) {
if (keys[i].indexOf("application/vnd.openxmlformats-officedocument") > -1) {
var endpoint = endpoints[keys[i]] "&access_token=" ScriptApp.getOAuthToken();
var mediaData = UrlFetchApp.fetch(endpoint).getBlob();
Logger.log(mediaData.getBytes().length)
Drive.Files.update({}, googleDocsFileId, mediaData);
break;
}
}
}
function resetSource() {
//pas nécessaire
var file = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("FileID").getValue();
var fileID = DriveApp.getFileById(file);
fileID.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.EDIT);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/411508.html
標籤:
上一篇:如何在appscript中使用谷歌任務(tasklist.tasks.get)?
下一篇:使用Google表格中的陣列以html格式創建資料串列,該串列可提供給GoogleApps腳本以自動完成文本輸入
