我正在嘗試在 google docs 上創建一個函式來清除檔案,(洗掉檔案中的所有內容,這是我目前所擁有的:
function onOpen() {
let ui = DocumentApp.getUi();
ui.createMenu('Extras')
.addItem('Purge Document', 'myFunction')
.addToUi();
};
function myFunction() {
var ui = DocumentApp.getUi();
var result = ui.alert(
'Purge?',
'Are you sure you want to purge the document? It will delete EVERYTHING. This is irreversible.',
ui.ButtonSet.YES_NO);
// responses
if (result == ui.Button.YES) {
// Clicked Yes ^^^
ui.alert('Purging...');
purge()
} else {
// User clicked No vvv
}
}
function purge(doc){
[heres where I need help]
}
有誰能夠幫助我?謝謝。
uj5u.com熱心網友回復:
可能像這樣的事情可以完成這項作業:
function purge() {
var doc = DocumentApp.getActiveDocument()
try { doc.getBody().clear() } catch(e) {}
try { doc.getFooter().clear() } catch(e) {}
try { doc.getHeader().clear() } catch(e) {}
}
電子表格的代碼,以防萬一:
function purge() {
SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach(s => s.clear());
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/358791.html
