-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only set text of paragraphs with placeholders
To avoid overwriting runs which contain metainformation (e.g. page number in footer), text replacement is only done for paragraphs which contain placeholders.
- Loading branch information
1 parent
f651da0
commit ec1b351
Showing
5 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ plugins { | |
} | ||
|
||
group 'com.docutools' | ||
version = '2.0.2' | ||
version = '2.0.3' | ||
|
||
java { | ||
toolchain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/java/com/docutools/jocument/sample/placeholders/TextPlaceholder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.docutools.jocument.sample.placeholders; | ||
|
||
import com.docutools.jocument.GenerationOptions; | ||
import com.docutools.jocument.impl.word.CustomWordPlaceholderData; | ||
import com.docutools.jocument.impl.word.WordUtilities; | ||
import java.util.Locale; | ||
import org.apache.poi.xwpf.usermodel.IBody; | ||
import org.apache.poi.xwpf.usermodel.IBodyElement; | ||
|
||
public class TextPlaceholder extends CustomWordPlaceholderData { | ||
@Override | ||
protected void transform(IBodyElement placeholder, IBody part, Locale locale, GenerationOptions options) { | ||
var paragraph = part.insertNewParagraph(WordUtilities.openCursor(placeholder).orElseThrow()); | ||
paragraph.createRun().setText("Live your life not celebrating victories, but overcoming defeats.".repeat(500)); | ||
WordUtilities.removeIfExists(placeholder); | ||
} | ||
} |
Binary file not shown.