N
N
nightY772018-10-30 12:34:46
Google Apps Script
nightY77, 2018-10-30 12:34:46

Google sheets script how to convert data from sheet to xl format or .csv?

Please help with converting data from google spreadsheet to xl or .csv file for sending by email. Didn't find a suitable method.
My code throws an attachments argument error:
var sSheet = SpreadsheetApp.openById('xxxxxxxxxxxxxxxxxxx');
var sheetLink = sSheet.getActiveSheet();
var values ​​= sheetLink.getDataRange().getValues();
var text = ContentService.createTextOutput().append(values)
MailApp.sendEmail(
'[email protected]',
'Report',
'Catch',
{attachments: [text]}
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
8
8x8z, 2018-10-30
@8x8z

Did something like this once.
There was one point - you need to save the sheet of the table in a new file and send it already in a certain format. Below is part of the code saving in xlsx format. Full code here

var ssSend     = ssNew.getId()
  var sendFile   = Drive.Files.get(ssSend);
  var url        = sendFile.exportLinks[MimeType.MICROSOFT_EXCEL];
  var token      = ScriptApp.getOAuthToken();
  var response   = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' +  token
    }
  }); 
   

  var blobs   = [response.getBlob().setName(sendFileName)];
//  var sizeBlob = blobs[0].getBytes();
  
  var subject = ssSourceName;
  var message = 'Файл подготовлен и отправлен: ' + Utilities.formatDate(d, timeZone,'dd.MM.yyyy HH:mm:ss'); 
  MailApp.sendEmail(toMail, subject, message , {attachments: blobs });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question