我对编写与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);
}
答案 0 :(得分:0)
问题在于getCell()
是Range
的方法,而非Sheet
。从Range
获取Sheet
,然后在getCell()
对象上使用Range