TypeError:在对象工作表中找不到函数getCell [英] TypeError: Cannot find function getCell in object Sheet

查看:169
本文介绍了TypeError:在对象工作表中找不到函数getCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编码与Google Apps脚本和JavaScript相关的所有内容完全陌生.

I am completely new to coding anything related to Google Apps Script and JavaScript in general.

我已经根据需要调整了脚本,但是运行脚本时出现以下错误:

I've adapted a script to my needs, but I am getting the following error when I run it:

TypeError:在对象表中找不到函数getCell

TypeError: Cannot find function getCell in object Sheet

本质上,我试图获取单元格D4(4,4)中的值并将该值传递给变量emailTo.我显然做错了.脚本的其余部分应该可以正常工作.任何指导表示赞赏.

Essentially, I am trying to get the value in cell D4 (4,4) and pass that value to the variable emailTo. I'm obviously not doing it correctly. The rest of the script should work fine. Any guidance is appreciated.

// Sends PDF receipt
// Based on script by ixhd at https://gist.github.com/ixhd/3660885

// Load a menu item called "Receipt" with a submenu item called "E-mail Receipt"
// Running this, sends the currently open sheet, as a PDF attachment
function onOpen() {
  var submenu = [{name:"E-mail Receipt", functionName:"exportSomeSheets"}];
  SpreadsheetApp.getActiveSpreadsheet().addMenu('Receipt', submenu);  
}

function exportSomeSheets() {
  // Set the Active Spreadsheet so we don't forget
  var originalSpreadsheet = SpreadsheetApp.getActive();

  // Set the message to attach to the email.
  var message = "Thank you for attending !  Please find your receipt attached.";

  // Construct the Subject Line
  var subject = "Receipt";

  // THIS IS WHERE THE PROBLEM IS
  // Pull e-mail address from D4 to send receipt to
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var emailTo = sheet.getCell(4, 4).getValue();

  // Create a new Spreadsheet and copy the current sheet into it.
  var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");
  var projectname = SpreadsheetApp.getActiveSpreadsheet();
  sheet = originalSpreadsheet.getActiveSheet();
  sheet.copyTo(newSpreadsheet);

  // Find and delete the default "Sheet 1"
  newSpreadsheet.getSheetByName('Sheet1').activate();
  newSpreadsheet.deleteActiveSheet();

  // Make the PDF called "Receipt.pdf"
  var pdf = DocsList.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();
  var attach = {fileName:'Receipt.pdf',content:pdf, mimeType:'application/pdf'};

  // Send the  constructed email 
  MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});

  // Delete the wasted sheet
  DocsList.getFileById(newSpreadsheet.getId()).setTrashed(true);  
}

推荐答案

问题是getCell()Range的方法,而不是Sheet.从Sheet获取Range,然后在Range对象上使用getCell()

The issue is that getCell() is a method of Range, not Sheet. Get a Range from the Sheet, then use getCell() on the Range object

这篇关于TypeError:在对象工作表中找不到函数getCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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