google-apps-scriptgoogle-docsgoogle-docs-api

Get paragraphs of data out from a word doc


I have this google doc and I want to extract the text into an excel where each row has each product's service description. Some of the paragraphs are as below-

Adaptive Image Compression: Adaptive Image Compression detects the current network conditions between a client and an Akamai edge server. It may dynamically re-compress image files, reducing file size and assisting in faster transmission of the image file.

Adaptive Media Delivery: Adaptive Media Delivery is optimized for adaptive bit rate streaming. This provides a high-quality viewing experience across varying network types and speeds, including mobile. Adaptive Media Delivery delivers both live and on-demand streaming media; and, since it's built on Akamai, it provides scalability, reliability, availability, and reach.

Adaptive Media Player for Devices – Android SDK: Adaptive Media Player for Devices (Android SDK) is a software SDK. It enables audio and video playback in popular Android-based mobile and TV platform formats. The software is delivered in executable format without source code, and configuration is performed by developers with available configuration objects, parameters, and client-side APIs. Using the player does not require Akamai delivery Services.

Adaptive Media Player for Devices – Premier: Adaptive Media Player for Devices (Premiere) is a software SDK. It enables audio and video playback in popular mobile and TV platform formats. Premier includes business-critical third-party capabilities for monetization and measurement. The software is delivered in executable format without source code, and configuration is performed by developers with available configuration objects, parameters, and client-side APIs. Using the player does not require Akamai delivery Services.

There are more than 200 such paragraphs, how can I easily extract each in to a row in an excel or google sheet.

Please help


Solution

  • I believe your goal is as follows.

    In this case, how about the following sample script?

    Sample script:

    Please copy and paste the following script to the script editor of Google Apps Script. And, please set documentId, spreadsheetId, and sheetName.

    function myFunction() {
      const documentId = "###"; // Please set your Google Document ID.
      const spreadsheetId = "###"; // Please set your Google Spreadsheet ID.
      const sheetName = "Sheet1"; // Please set your sheet name.
    
      // Retrieve paragraphs from the Document.
      const paragraphs = DocumentApp.openById(documentId).getBody().getParagraphs();
      const values = paragraphs.map(p => [p.getText().trim()]).filter(String);
    
      // Put the paragraphs into a Spreadsheet.
      const sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
      sheet.clearContents().getRange(1, 1, values.length).setValues(values);
    }
    

    References: