The following code creates "new spreadsheet" and set "test" to cell A1
and copies the spreadsheet to "copied spreadsheet".
But "test" of cell A1 is set only to "new spreadsheet" but "copied spreadsheet". Is there some save() method to save a spreadsheet modified by gas?
// create spreadsheet named "new spreadsheet"
const spreadsheet = SpreadsheetApp.create('new spreadsheet');
const sheet = spreadsheet.getActiveSheet();
// set "test" to cell A1
sheet.getRange(1, 1).setValue('test');
// copy "new spreadsheet" to "copied spreadsheet"
// *but cell A1 of "copied spreadsheet" is unexpectedly blank.
DriveApp.getFileById(spreadsheet.getId()).makeCopy('copied spreadsheet');
What I really want to do is to modify spreadsheet cells and send it as an attachment file of a mail. But the same issue I wrote above happens. The modifications to cells are not applied to the attached spreadsheet.
GmailApp.sendEmail(
to,
subject,
body,
{
// *modifications to the spreadsheet by gas are ignored
attachments: spreadsheet,
}
);