Я думаю, что это может помочь вам
function myFunction(){
var ss = SpreadsheetApp.openById("YOUR_SPREADSHEET_ID");
var sheets = ss.getSheets();
var B2Values = [];
sheets.forEach(function(elt,index){
//Get all your email adresses
B2Values.push(sheets[index].getRange(2,2).getValue());
});
//For each sheet in your Spreadsheet, it create a temporary Spreadsheet
//who got only one sheet, with your sheet values,
// transform it as pdf, send the pdf by email to your B2 email adress and delete
//the temporary Spreadsheet
sheets.forEach(function(elt, index){
var temporarySS = SpreadsheetApp.create("NAME_OF_THE_FILE_WHO_WILL_BE_SENT");
var temporaryId = temporarySS.getId();
var dataToMove = sheets[index].getRange(1,1,sheets[index].getLastRow(),sheets[index].getLastColumn()).getValues();
var openingTemporarySS = SpreadsheetApp.openById(temporaryId);
dataToMove.forEach(function(elt){
openingTemporarySS.appendRow(elt);
})
MailApp.sendEmail({
to: B2Values[index],
subject: "YOUR_SUBJECT",
attachments: [openingTemporarySS.getAs('application/pdf')]
})
DriveApp.getFileById(temporaryId).setTrashed(true);
});
}
И это другая версия, я думаю, если у вас много листов, вы должны использовать эту:
function myFunction(){
var ss = SpreadsheetApp.openById("YOUR_SPREADSHEET_ID");
var sheets = ss.getSheets();
var B2Values = [];
sheets.forEach(function(elt,index){
//Get all your email adresses
B2Values.push(sheets[index].getRange(2,2).getValue());
});
var temporarySS = SpreadsheetApp.create("NAME_OF_THE_FILE_WHO_WILL_BE_SENT");
var temporaryId = temporarySS.getId();
var openingTemporarySS = SpreadsheetApp.openById(temporaryId);
sheets.forEach(function(elt, index){
var dataToMove = sheets[index].getRange(1,1,sheets[index].getLastRow(),sheets[index].getLastColumn()).getValues();
dataToMove.forEach(function(elt){
openingTemporarySS.appendRow(elt);
})
MailApp.sendEmail({
to: B2Values[index],
subject: "YOUR_SUBJECT",
attachments: [openingTemporarySS.getAs('application/pdf')]
})
openingTemporarySS.deleteRows(1,openingTemporarySS.getLastRow());
});
DriveApp.getFileById(temporaryId).setTrashed(true);
}