1

私は、Google Apps Script および JavaScript 全般に関連するものをコーディングするのはまったく初めてです。

必要に応じてスクリプトを調整しましたが、実行すると次のエラーが発生します。

TypeError: オブジェクト Sheet に関数 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