LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Monday, April 29, 2019

Googleドキュメントのテキストをプレーンテキストで取得したい


こういうドキュメントがあって
入力されているテキストをスクリプトで取得してログに出してみる


今回ドキュメントに書いたテキスト

Googleドキュメントのテキストを取得したい。
スクリプトでドキュメントを取得して、プレーンテキストにしてログに出してみる。



コード.gs
function getDocText() {
  var id = "1oMMKqivcIXq6etXJT-8Jq84RU-5Bt955_b3o9BCdGlQ";
  var doc = DocumentApp.openById(id);
  var body = doc.getBody().getText();
  Logger.log(body);
}
意訳
この機能がやること
ファイルIDを指定して
そのドキュメントを取得して
テキストを取得して
ログに出す




実行結果


参考

Document Service
https://developers.google.com/apps-script/reference/document/

Class DocumentApp
https://developers.google.com/apps-script/reference/document/document-app

Class Body
https://developers.google.com/apps-script/reference/document/body

getText()
https://developers.google.com/apps-script/reference/document/body#getText()

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...