Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.deividasstr:docx-word-replacer:0.4'
}
dependencies {
implementation("com.github.deividasstr:docx-word-replacer:0.4")
}
<dependency>
<groupId>com.github.deividasstr</groupId>
<artifactId>docx-word-replacer</artifactId>
<version>0.4</version>
</dependency>
libraryDependencies += "com.github.deividasstr" % "docx-word-replacer" % "0.4"
:dependencies [[com.github.deividasstr/docx-word-replacer "0.4"]]
Wrapper for Apache poi-ooxml java lib explicitly dealing with docx files - replaces words/bookmarks/markers.
This is quite a simple wrapper around medium level Apache poi-ooxml lib. When I needed this functionality it took me unreasonably long time to achieve it. Also this lib is my first shot at open source.
Simply add path to jitpack repo and dependency:
Gradle
Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.deividasstr:docx-word-replacer:0.4'
}
Maven
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.deividasstr</groupId>
<artifactId>docx-word-replacer</artifactId>
<version>0.4</version>
</dependency>
API class is WordReplacer. Init it with docx file or native apache XWPFDocument, then call replaceWordsInText(String bookmark, String replacement)
or replaceWordsInTables(String bookmark, String replacement)
to replace as many times as needed.
Then retrieve the XWPFDocument (if needed) by getModdedXWPFDoc()
or get file by saveAndGetModdedFile()
providing the filepath or file itself as arguments.
All appropriate runs of the document are checked for bookmark string. Sometimes bookmark string is scattered across few runs, so the lib looks at the currently checked run, previous and next run for bookmark.
So basically if the bookmark in the document was not replaced, text is scattered across more than 3 runs or paragraphs.
This project is licensed under the Apache 2.0 because of the Apache POI dependency under same license. See the LICENSE.md file for details.