OfficeScripts to create a word document and add data

Here’s a sample OfficeScript that demonstrates how to create a Word document, add paragraphs of data, and save the document:

function createWordDocument() {
  // Create a Word document
  var document = context.document.create();

  // Add paragraphs of data to the document
  document.body.insertParagraph("Hello, World!", "Start");
  document.body.insertParagraph("This is a sample paragraph.", "End");

  // Save the document
  document.save("SampleDocument.docx");
}

In this example, the createWordDocument function performs the following steps:

  1. It creates a new Word document using the context.document.create() method.

  2. It adds paragraphs of data to the document using the insertParagraph method. The first parameter is the text content of the paragraph, and the second parameter specifies where to insert the paragraph (“Start” or “End”).

  3. Finally, it saves the document with the specified file name using the document.save() method.

You can call the createWordDocument function to create the Word document and add paragraphs of data. The document will be saved with the name “SampleDocument.docx”.

Please note that OfficeScripts for Word are currently only supported in Word for the web, and you need to have the appropriate permissions to create and save documents.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech