1

一般来说,我对与 Google Apps 脚本和 JavaScript 相关的任何内容都完全陌生。

我已经根据自己的需要调整了一个脚本,但是当我运行它时出现以下错误:

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

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

// 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);  
}
4

1 回答 1

1

问题是那getCell()是一种方法Range,而不是SheetRange从 中获取 a Sheet,然后getCell()Range对象上使用

于 2013-05-18T00:52:05.057 回答