检查Google电子表格中是否存在工作表 [英] check for existence of a sheet in google spreadsheets

查看:58
本文介绍了检查Google电子表格中是否存在工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查myname 表格存在于Google脚本中,以避免在现有名称上使用insertSheet的错误?

How to I check if myname sheet exist in google scripts, to avoid errors using insertSheet on an existing name?

关注不起作用

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var itt = ss.getSheetByName('_EmailList');
  if (! (itt.hasNext())){
    ss.insertSheet('_EmailList');}

推荐答案

它不起作用,因为'itt'是Sheet类的实例,不具有'hasNext()'方法.请确保在尝试编写代码之前先阅读文档-这可以确保为您省去很多麻烦 https://developers.google.com/apps-script/reference/spreadsheet/sheet

It doesn't work because 'itt' is the instance of Sheet class that doesn't have 'hasNext()' method. Please be sure to review the docs before attempting to write code - this is guaranteed to save you a lot of trouble https://developers.google.com/apps-script/reference/spreadsheet/sheet

如果具有指定名称的工作表不存在,则getSheetByName()将返回空引用.

If the sheet with the specified name doesn't exist, getSheetByName() will return a null reference.

 var itt = ss.getSheetByName('_EmailList');

 if (!itt) {

   ss.insertSheet('_EmailList');
}

这篇关于检查Google电子表格中是否存在工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆