DEV Community

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

Posted on

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)