メインコンテンツにスキップ

MicrosoftDocsApp

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.

AI Summary

MicrosoftDocsApp

A library that lets Google Apps Script treat Word, Excel and PowerPoint files on Google Drive through the native Document, Spreadsheet and Slides services

Target Users

Intermediate Google Apps Script developers who need to programmatically read and update Office files on Drive for internal automation tools

Problems Solved

Office files cannot be manipulated with GAS Document/Spreadsheet/Slides services without manual conversion, adding complexity to automation

Tags

Main Features

1
Operate Office files with native GAS APIs

Returns instances of DocumentApp, SpreadsheetApp or SlidesApp after automatic conversion, so existing code and IDE auto-completion work unchanged

2
Automatic convert-save workflow

Just call setFileId, getDocument/Spreadsheet/Slide and saveAndClose; the library handles conversion and overwriting the original file

3
Temporary file cleanup

Calling end() removes the temporary Google format file, keeping Drive tidy

Usage Examples

Retrieve text from a DOCX file

function getDocxText() {
  const fileId = "###";                 // File ID of the DOCX on Drive
  const MD = MicrosoftDocsApp.setFileId(fileId); // Initialize the library
  const doc = MD.getDocument();         // Converts Word → Google Document
  const text = doc.getBody().getText(); // Read body text
  console.log(text);
  MD.end();                             // Clean up temporary file
  // DocumentApp.getActiveDocument();    // Keep for scope detection
}

Append a row to an XLSX file and save

function appendToXlsx() {
  const fileId = "###";                     // XLSX file ID
  const MD = MicrosoftDocsApp.setFileId(fileId);
  const ss = MD.getSpreadsheet();            // Excel → Google Sheet
  ss.getSheets()[0].appendRow([new Date(), "sample data"]); // Add new row
  MD.saveAndClose();                         // Write back to original XLSX
  MD.end();                                  // Remove temp file
  // SpreadsheetApp.getActiveSpreadsheet();  // Scope detection
}