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:
It creates a new Word document using the
context.document.create()
method.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”).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.