DEV Community

Cover image for Search & Replace Texts in DOCX
satyajit nayak
satyajit nayak

Posted on

4 1

Search & Replace Texts in DOCX

Search & Replace Texts in DOCX

Hey guys, I have created a package name edit-office-file which can search & replace multiple text strings inside a DOCX file as well other office files.

  1. First install the pkg: npm i edit-office-files.

  2. Usage style:


import {SearchAndReplace} from 'edit-office-files';

async function main() {
  const searchTexts = ['Hello World', 'are You', 'coloured'];
  const replacementTexts = ['REPLACEMENT1', 'REPLACEMENT2', 'REPLACEMENT3'];
  const reader = new SearchAndReplace('assets/document.docx', searchTexts, replacementTexts, 'updated.docx');
  await reader.process();
}

main();

Enter fullscreen mode Exit fullscreen mode

Here is the github link for the project.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more