Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年1月19日土曜日

テキストファイルをGoogleドキュメントで開きたい


ドキュメントの場合はMIME TYPEをこうすると良いらしい
mimeType: 'application/vnd.google-apps.document'


事前準備





コード.gs
function createDocFromText() {
  var url = "https://drive.google.com/file/d/ID/view?usp=sharing";//テキストファイルのURL
  var id = url.split("/d/")[1].split("/")[0];
  var file = DriveApp.getFileById(id);
  var name = file.getName();
  var blob = file.getBlob();

  var file = {
    title: name,
    mimeType: 'application/vnd.google-apps.document'
  };
  
  file = Drive.Files.insert(file, blob);
  var id = file.id;
  var docUrl = "https://docs.google.com/document/d/" + id + "/edit";
  Logger.log(docUrl);
}



参考

Supported MIME Types
https://developers.google.com/drive/api/v3/mime-types

Uploading files
https://developers.google.com/apps-script/advanced/drive#uploading_files



Latest post

Google Classroom API でクラスの一覧を取得したい

自分が指導・参加しているクラスの名称とIDを取得するコードを試しました 下記 Code.gs では pageSize で 100 を設定していますが 必ず 100件 返ってくるとは限らないらしいです https://developers.google.com/workspace/...