Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!