Google apps script 如何使用apps脚本查找google文档是否为空
我想知道文件是否是空的 我试过了Google apps script 如何使用apps脚本查找google文档是否为空,google-apps-script,google-docs,google-docs-api,Google Apps Script,Google Docs,Google Docs Api,我想知道文件是否是空的 我试过了 if (DocumentApp.getActiveDocument().getBody().getText().length < 1); { showAlert('Document is empty') return; } if(DocumentApp.getActiveDocument().getBody().getText().length
if (DocumentApp.getActiveDocument().getBody().getText().length < 1); {
showAlert('Document is empty')
return;
}
if(DocumentApp.getActiveDocument().getBody().getText().length<1);{
showAlert('文档为空')
返回;
}
但这会绕过图像或文档中的任何其他特殊项
如何确定文档为空或完全为空?请将此视为几个答案之一。比较文档和新文档的文件大小如何?它发现,当从包含一些图像、文本和注释的文档中删除所有图像、文本和注释时,大小变为新文档的大小。我认为通过使用这个,它可以知道文档是否为空 示例脚本: 注:
- 因为我担心每个环境的文件大小可能不同,所以在示例脚本中,我使用
Document检索了文件大小。此temp
文档在脚本的最后一步被删除temp
var id = "### Document ID ###"; // Please input ID here.
var tempId = DocumentApp.create("temp").getId();
var newdocument = DriveApp.getFileById(tempId).getBlob().getBytes().length;
var document = DriveApp.getFileById(id).getBlob().getBytes().length;
if (newdocument == document) {
Logger.log("Empty")
}
DriveApp.removeFile(DriveApp.getFileById(tempId));