Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda