{"id":19651760,"url":"https://github.com/tanaikech/microsoftdocsapp","last_synced_at":"2025-10-29T07:37:20.352Z","repository":{"id":214258716,"uuid":"736088273","full_name":"tanaikech/MicrosoftDocsApp","owner":"tanaikech","description":"This is a Google Apps Script library for using Microsoft Docs files (Word, Excel, and PowerPoint files) using Document service, Spreadsheet service, and Slides Service of Google Apps Script.","archived":false,"fork":false,"pushed_at":"2023-12-27T00:46:13.000Z","size":4197,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T19:49:10.470Z","etag":null,"topics":["gas-library","google-apps-script","google-apps-script-library","google-docs","library","microsoft-docs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanaikech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-27T00:42:21.000Z","updated_at":"2025-04-04T00:18:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ecba1d7-d822-496f-b3bf-d3503e17522a","html_url":"https://github.com/tanaikech/MicrosoftDocsApp","commit_stats":null,"previous_names":["tanaikech/microsoftdocsapp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tanaikech/MicrosoftDocsApp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FMicrosoftDocsApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FMicrosoftDocsApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FMicrosoftDocsApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FMicrosoftDocsApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanaikech","download_url":"https://codeload.github.com/tanaikech/MicrosoftDocsApp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FMicrosoftDocsApp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281584739,"owners_count":26526169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gas-library","google-apps-script","google-apps-script-library","google-docs","library","microsoft-docs"],"created_at":"2024-11-11T15:07:53.430Z","updated_at":"2025-10-29T07:37:20.347Z","avatar_url":"https://github.com/tanaikech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MicrosoftDocsApp\r\n\r\n\u003ca name=\"top\"\u003e\u003c/a\u003e\r\n[MIT License](LICENCE)\r\n\r\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\r\n\r\n# Overview\r\n\r\nThis is a Google Apps Script library for using Microsoft Docs files (Word, Excel, and PowerPoint files) using [Document service](https://developers.google.com/apps-script/reference/document), [Spreadsheet service](https://developers.google.com/apps-script/reference/spreadsheet), and [Slides Service](https://developers.google.com/apps-script/reference/slides) of Google Apps Script.\r\n\r\n![](images/fig1.png)\r\n\r\n\u003ca name=\"description\"\u003e\u003c/a\u003e\r\n\r\n# Description\r\n\r\nRecently, Microsoft Docs files (Word, Excel, and PowerPoint files) could be manually edited by opening it on Google Drive using the browser. This is good news for a lot of users. With this situation, the URLs of Microsoft Docs files were changed. For example, when a Microsoft Word file (DOCX) is opened on Google Drive with the browser, the URL is `https://docs.google.com/document/d/###/edit`. `###` of this URL is the file ID of the DOCX file on Google Drive. This URL is the same as that of Google Document while the length of the file ID is different. From this situation, it might be guessed that the Document service of Google Apps Script might be able to be used for DOCX files.\r\n\r\nRecently, I sometimes saw this situation at Stackoverflow. However, unfortunately, in the current stage, Microsoft Docs files cannot be directly used with the Document service, Spreadsheet service, and Slides Service of Google Apps Script. Fortunately, when Microsoft Docs files are converted to Google Docs files, those services can be used. I'm worried that this process might be a bit complicated for users.\r\n\r\nSo, I created this library MicrosoftDocsApp. When MicrosoftDocsApp is used, Microsoft Docs files can be used with Document service, Spreadsheet service, and Slides Service of Google Apps Script using a simple script.\r\n\r\n# Library's project key\r\n\r\n```\r\n1B0eoHz03BVtSZhJAocaGNq94RjoXocz8xGMaLzwVdmAvYW5k8s5Yd360\r\n```\r\n\r\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\r\n\r\n# Usage\r\n\r\n## 1. Install library\r\n\r\nIn order to use this library, please install the library as follows.\r\n\r\n1. Create a GAS project.\r\n\r\n   - You can use this library for the GAS project of both the standalone and container-bound script types.\r\n\r\n1. [Install this library](https://developers.google.com/apps-script/guides/libraries).\r\n\r\n   - Library's project key is **`1B0eoHz03BVtSZhJAocaGNq94RjoXocz8xGMaLzwVdmAvYW5k8s5Yd360`**.\r\n\r\n# Scopes\r\n\r\nThis library uses the following 2 scopes.\r\n\r\n- `https://www.googleapis.com/auth/script.external_request`\r\n- `https://www.googleapis.com/auth/drive`\r\n\r\nHowever, when you want to use DOCX file with Document service, a scope of `https://www.googleapis.com/auth/documents` is required to be used. Similarly, when you want to use XLSX and PPTX files with Spreadsheet and Slides service, respectively, the scopes of `https://www.googleapis.com/auth/spreadsheets` and `https://www.googleapis.com/auth/presentations` are required to be used. In the following sample scripts, the scopes are also considered. Please don't worry.\r\n\r\n# API\r\n\r\nThis library uses Drive API v3. If an error is related to Drive API, please enable Drive API v3 at Advanced Google services.\r\n\r\n# IMPORTANT\r\n\r\nWhen Microsoft Docs files (Word, Excel, and PowerPoint files) are updated, this library overwrites Microsoft Docs files. So, I would like to recommend testing this library after you back up your original files.\r\n\r\n# Limitations\r\n\r\n- In the current stage, Microsoft Docs files are not completely same with Google Docs files. When Microsoft Docs files are updated using Document service, Spreadsheet service, and Slides service, there might be a situation that the updated result is completely same between Microsoft Docs files and Google Docs files.\r\n\r\n# Methods\r\n\r\n| Methods                           | Description                                                              |\r\n| :-------------------------------- | :----------------------------------------------------------------------- |\r\n| [setFileId](#setfileid)           | Set file ID of Microsoft Docs files (Word, Excel, and PowerPoint files)  |\r\n| [getDocument](#getdocument)       | Get Class Document of Document converted from Word file.                 |\r\n| [getSpreadsheet](#getspreadsheet) | Get Class Spreadsheet of Spreadsheet converted from Excel file.          |\r\n| [getSlide](#getslide)             | Get Class Presentation of Presentation converted from PowerPoint file.   |\r\n| [saveAndClose](#saveandclose)     | If you write something, Microsoft Docs files are updated by this method. |\r\n| [end](#end)                       | Temporal file of converted Google Docs file is deleted.                  |\r\n\r\nIn this library, the auto-completion can be used as follows.\r\n\r\n![](images/fig2.gif)\r\n\r\n\u003ca name=\"setfileid\"\u003e\u003c/a\u003e\r\n\r\n## setFileId\r\n\r\nSet file ID of Microsoft Docs files (Word, Excel, and PowerPoint files)\r\n\r\nSample script is as follows.\r\n\r\n```javascript\r\nconst fileId = \"###\"; // File ID of one of Microsoft Docs files (Word, Excel, and PowerPoint files)\r\nconst MD = MicrosoftDocsApp.setFileId(fileId);\r\n```\r\n\r\n\u003ca name=\"getdocument\"\u003e\u003c/a\u003e\r\n\r\n## getDocument\r\n\r\nGet Class Document of Document converted from Word file.\r\n\r\nSample script is as follows.\r\n\r\nIf you want to only get values from DOCX file, you can use the following sample script.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of DOCX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const doc = MD.getDocument();\r\n\r\n  const res = doc.getBody().getText();\r\n  console.log(res);\r\n  MD.end();\r\n\r\n  // DocumentApp.getActiveDocument(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/documents\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\nIf you want to put values to DOCX file, you can use the following sample script. In this case, please use `saveAndClose()`. By this, DOCX file is updated.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of DOCX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const doc = MD.getDocument();\r\n\r\n  const body = doc.getBody();\r\n  body.appendParagraph(\"sample\");\r\n  MD.saveAndClose();\r\n  MD.end();\r\n\r\n  // DocumentApp.getActiveDocument(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/documents\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\n\u003ca name=\"getspreadsheet\"\u003e\u003c/a\u003e\r\n\r\n## getSpreadsheet\r\n\r\nGet Class Spreadsheet of Spreadsheet converted from Excel file.\r\n\r\nSample script is as follows.\r\n\r\nIf you want to only get values from XLSX file, you can use the following sample script.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of XLSX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const ss = MD.getSpreadsheet();\r\n\r\n  const res = ss.getSheets()[0].getDataRange().getValues();\r\n  console.log(res);\r\n  MD.end();\r\n\r\n  // SpreadsheetApp.getActiveSpreadsheet(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/spreadsheets\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\nIf you want to put values to XLSX file, you can use the following sample script. In this case, please use `saveAndClose()`. By this, XLSX file is updated.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of XLSX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const ss = MD.getSpreadsheet();\r\n\r\n  ss.getSheets()[0].appendRow([new Date(), \"sample\"]);\r\n  MD.saveAndClose();\r\n  MD.end();\r\n\r\n  // SpreadsheetApp.getActiveSpreadsheet(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/spreadsheets\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\n\u003ca name=\"getslide\"\u003e\u003c/a\u003e\r\n\r\n## getSlide\r\n\r\nGet Class Presentation of Presentation converted from PowerPoint file.\r\n\r\nSample script is as follows.\r\n\r\nIf you want to only get values from PPTX file, you can use the following sample script. In this case, a text is retrieved from a shape on the first slide.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of PPTX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const s = MD.getSlide();\r\n\r\n  const res = s.getSlides()[0].getShapes()[0].getText().asString();\r\n  console.log(res);\r\n  MD.end();\r\n\r\n  // SlidesApp.getActivePresentation(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/presentations\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\nIf you want to put values to PPTX file, you can use the following sample script. In this case, please use `saveAndClose()`. By this, PPTX file is updated.\r\n\r\n```javascript\r\nfunction sample() {\r\n  const fileId = \"###\"; // File ID of PPTX file.\r\n\r\n  const MD = MicrosoftDocsApp.setFileId(fileId);\r\n  const s = MD.getSlide();\r\n\r\n  s.getSlides()[0]\r\n    .insertShape(SlidesApp.ShapeType.RECTANGLE, 0, 0, 100, 100)\r\n    .getText()\r\n    .setText(\"new text\");\r\n  MD.saveAndClose();\r\n  MD.end();\r\n\r\n  // SlidesApp.getActivePresentation(); // This comment line is used for automatically detecting a scope \"https://www.googleapis.com/auth/presentations\" by the script editor. So, please don't remove this comment line.\r\n}\r\n```\r\n\r\n- In this script, a rectangle shape including a text is created to the first slide.\r\n\r\n\u003ca name=\"saveandclose\"\u003e\u003c/a\u003e\r\n\r\n## saveAndClose\r\n\r\nIf you write something, Microsoft Docs files are updated by this method.\r\n\r\nYou can see how to use this method at the above sample scripts.\r\n\r\n\u003ca name=\"end\"\u003e\u003c/a\u003e\r\n\r\n## end\r\n\r\nTemporal file of converted Google Docs file is deleted.\r\n\r\nYou can see how to use this method at the above sample scripts.\r\n\r\n---\r\n\r\n\u003ca name=\"licence\"\u003e\u003c/a\u003e\r\n\r\n# Licence\r\n\r\n[MIT](LICENCE)\r\n\r\n\u003ca name=\"author\"\u003e\u003c/a\u003e\r\n\r\n# Author\r\n\r\n[Tanaike](https://tanaikech.github.io/about/)\r\n\r\n[Donate](https://tanaikech.github.io/donate/)\r\n\r\n\u003ca name=\"updatehistory\"\u003e\u003c/a\u003e\r\n\r\n# Update History\r\n\r\n- v1.0.0 (December 27, 2023)\r\n\r\n  1. Initial release.\r\n\r\n[TOP](#top)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fmicrosoftdocsapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanaikech%2Fmicrosoftdocsapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fmicrosoftdocsapp/lists"}