Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何使用apps脚本查找google文档是否为空_Google Apps Script_Google Docs_Google Docs Api - Fatal编程技术网

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('文档为空')
返回;
}
但这会绕过图像或文档中的任何其他特殊项


如何确定文档为空或完全为空?

请将此视为几个答案之一。比较文档和新文档的文件大小如何?它发现,当从包含一些图像、文本和注释的文档中删除所有图像、文本和注释时,大小变为新文档的大小。我认为通过使用这个,它可以知道文档是否为空

示例脚本: 注:
  • 因为我担心每个环境的文件大小可能不同,所以在示例脚本中,我使用
    temp
    Document检索了文件大小。此
    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));