1

I have written a script to pull daily an attachment that is sent with the same description daily on a xlsm attachment into a google sheet so that it is in a more useable format for the desired audience, but the script is currently failing.

The email also has a picture embedded into the footer, which could also be cuasing part of the problem.

Script i am using is below and it is now failing at line 18

Unsure of where to go with this, thanks in advance

function importxlsmFromGmail() {

  var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("INPUT");
  ws.getRange("A1:M").clearContent();

  var threads = GmailApp.search('from:Services@customer.com subject:"Routes Delay"');
  var message = threads[0].getMessages()[0];
  var attachment = message.getAttachments()[0];
  // Is the attachment a xlsm file
  attachment.setContentTypeFromExtension();
  
  Logger.log(attachment.getContentType())
  if (attachment.getContentType() === "application/vnd.ms-excel.sheet.macroenabled.12") {
  attachment.setContentType(MimeType.MICROSOFT_EXCEL);
}{

    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("INPUT");
    var xlsmData = Utilities.parsexlsm(attachment.getDataAsString(), ",");  // Error occurs here

    // Remember to clear the content of the sheet before importing new data
    //sheet.clearContents().clearFormats();
    sheet.getRange(1, 1, xlsmData.length, csvData[0].length).setValues(xlsmData);
    var total_lenght = sheet.getRange("A1:A").getValues();
    var last_row = total_lenght.filter(String).length;
    //console.log(Alast)
    // var cell = sheet.getRange("F2:F" & last_row);
    // cell.setNumberFormat("0.0");

  }
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
MPW617
  • 11
  • 1
  • Welcome to [so]. The script fails because `parsexlsm` method is not part of [Class Utilities](https://developers.google.com/apps-script/reference/utilities/utilities) (that should be said in the error message). – Rubén Apr 28 '22 at 19:43

0 Answers0