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

207
Visualizações
Is there a way to read and load an .odt file into a variable with DriveApp

I have been writing a script thats supposed to take information from several .odt files and insert that into several different spreadsheet cells and im stuck with the question of how to get that text into a variable so i can do some regex stuff to get the actual information i want. Problem is this:

let text = DocumentApp.openById(idString).getBody();

when i execute that, i get this error

Error   
Exception: Invalid argument

I've read here that one of the issues might be that DriveApp ids are not the same as DocumentApp ids, in that case, ive tried getting the proper id first, but in that case, it still doesnt seem to work.

let text = DriveApp.getFileById(idString).getBlob;

now, that technically works, however, i still dont know how to retrieve the body/text/contents (really, however you wanna call it) from the file. ive tried getDataAsString, but that just gets me well, everything but what i care about.

Hopefully someone can help here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Unfortunately, odt file cannot be directly opened as the readable data. So, in this case, in order to retrieve the text from odt data, I would like to propose the following flow.

  1. Convert odt data to Google Document using Drive API.
  2. Open the created Google Document using the Document service (DocumentApp).
  3. Retrieve the text from the Document.

When this flow is reflected in a sample script of Google Apps Script, it becomes as follows.

Sample script:

Before you use this script, please enable Drive API at Advanced Google services.

function myFunction() {
  const fileId = "###"; // Please set the file ID of odt file.

  const id = Drive.Files.copy({title: "temp", mimeType: MimeType.GOOGLE_DOCS}, fileId).id;
  const doc = DocumentApp.openById(id);
  const text = doc.getBody().getText();
  console.log(text);
}
  • When this script is run, the above flow is run. By this, you can retrieve the text data from odt file.
  • The converted document is created as a temporal file in the root folder. You can remove it with DriveApp.getFileById(id).setTrashed(true) after the script was finished.

Reference:

  • Files: copy
about 4 years ago · Juan Pablo Isaza Relatório
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