Edit Word in Node SDK

Use REST API to edit Word in JavaScript programmatically

When developers modify a Word document with this JavaScript library, what is actually being edited is the Document Object Model (DOM). Thus, almost any changes can be made to the Word document represented as DOM. With the provided Node SDK, developers can easily edit a document: modify text, update tables, add images and so on. Just load a Word, make the necessary changes programmatically and export the result to the same or any supported save format.

View code snippet

Edit Word in JavaScript using REST API

Our Node library gives developers the ability to modify a Word document directly by editing its Document Object Model (DOM), which means no additional software needs to be installed.

Edit text in Word file using JavaScript

The most popular case to edit a Word file is text editing. With the given software solution, you can add, modify or delete text using JavaScript within the document.

Edit table in Word file using JavaScript

Another popular Word editing option is table editing. Our Node SDK allows you to work with tables and text in table cells.

JavaScript developers can add or remove table and table cells, as well as add, edit and remove text within them.

Add an image to Word file using JavaScript

Besides editing text and tables in Word, there is another common option: adding images to a document in JavaScript. Node developers can also add an image into a Word file using DOM.

Edit Word programmatically

Try this powerful Node SDK and evaluate some options in Word document editing. Using the following example, load your Word document and make some changes: add text, add a table and a table cell with text or insert an image into the Word document:

Upload a document you want to modify
Run code
Upload an image you want insert
Select the target format from the list
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input.docx");
const requestParagraph = new model.ParagraphInsert({
    text: "Morbi enim nunc faucibus a."
})
const insertParagraphRequest = new model.InsertParagraphOnlineRequest({
    document: requestDocument,
    paragraph: requestParagraph
});

wordsApi.insertParagraphOnline(insertParagraphRequest)
.then((insertParagraphResult) => {    
    const requestDocument = insertParagraphResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "docx"
    });

    wordsApi.convertDocument(convertDocument)
    .then((convertDocumentResult) => {
        console.log("Result of ConvertDocument: ", convertDocumentResult);
    });
});
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input.docx");
const requestTable = new model.TableInsert({
    columnsCount: 1,
    rowsCount: 2
})
const insertTableRequest = new model.InsertTableOnlineRequest({
    document: requestDocument,
    table: requestTable,
    nodePath: ""
});

wordsApi.insertTableOnline(insertTableRequest)
.then((insertTableResult) => {    
    const requestDocument = insertTableResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "docx"
    });

    wordsApi.convertDocument(convertDocument)
    .then((convertDocumentResult) => {
        console.log("Result of ConvertDocument: ", convertDocumentResult);
    });
});
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input1.docx");
const requestDrawingObject = new model.DrawingObjectInsert({
    height: 0,
    left: 0,
    top: 0,
    width: 0,
    relativeHorizontalPosition: model.DrawingObjectInsert.RelativeHorizontalPositionEnum.Margin,
    relativeVerticalPosition: model.DrawingObjectInsert.RelativeVerticalPositionEnum.Margin,
    wrapType: model.DrawingObjectInsert.WrapTypeEnum.Inline
})
const requestImageFile = fs.createReadStream("Input2.docx");
const insertDrawingObjectRequest = new model.InsertDrawingObjectOnlineRequest({
    document: requestDocument,
    drawingObject: requestDrawingObject,
    imageFile: requestImageFile,
    nodePath: "sections/0"
});

wordsApi.insertDrawingObjectOnline(insertDrawingObjectRequest)
.then((insertDrawingObjectResult) => {    
    const requestDocument = insertDrawingObjectResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "docx"
    });

    wordsApi.convertDocument(convertDocument)
    .then((convertDocumentResult) => {
        console.log("Result of ConvertDocument: ", convertDocumentResult);
    });
});
Run code
  
Copy JavaScript code to the clipboard

How to Edit Word in JavaScript

  1. Install Aspose.Words Cloud for Node
  2. Add a library reference (import the library) to your JavaScript project
  3. Load Word to edit in JavaScript
  4. Insert content at the beginning of Word
  5. Download the result document from the cloud storage

JavaScript library to use DOCX editing

Install 'Aspose.Words Cloud SDK for Node.js' using NPM package manager. Run npm install asposewordscloud --save from the command line to install the SDK via the NPM package manager. As an alternative, you can manually clone Aspose.Words Cloud SDK for Node.js source code from GitHub and use it in your project. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

  • @types/request (version 2.48.3+)
  • lodash (version 4.17.15+)
  • lodash.template (version 4.5.0+)
  • request (version 2.88.0+)
  • request-debug (version 0.2.0+)

Refer to the Repository Documentation to see more details.

Other supported file formats

You can perform edit operation for other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.