Answer the question
In order to leave comments, you need to log in
How to save one sheet from Google Sheets to xlsx format and send it by email?
Good afternoon!
The task is as follows: there is a book with several sheets in it. One of the sheets must be saved in a separate book, reformatted in excel, and sent by mail.
I understand how to create a new book empty. But how to insert a sheet from another into it and convert it to xlsx, I don’t know.
If someone can help with the lines of code, I will be very grateful
Answer the question
In order to leave comments, you need to log in
In fact, this task is easy to google.
For example, you want to save the "My Super Sheet" sheet.
/**
*
*/
function runSheet() {
var spec = ['Мой супер лист'];
var spreadsheet = SpreadsheetApp.openById(
'ABCD1234'
).copy('tmp');
spec.forEach(function(sheetName) {
var dr = spreadsheet.getSheetByName(sheetName).getDataRange();
dr.setValues(dr.getValues());
});
spreadsheet.getSheets().forEach(function(sheet) {
if (spec.indexOf(sheet.getName()) < 0) spreadsheet.deleteSheet(sheet);
});
var spreadsheetId = spreadsheet.getId();
var file = exportSpreadsheetToFile_(spreadsheetId, 'xlsx');
DriveApp.getFileById(spreadsheetId).setTrashed(true);
return file;
}
exportSpreadsheetToFile_
can be found here . MailApp.sendEmail({
to: "[email protected]",
subject: "Logos",
attachments: [runSheet().getBlob()]
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question