Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
Script is failing when trying to pull a xlsm attachment from my email daily

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");

  }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda