Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Each text shape can contain multiple paragraphs, and each paragraph can have multiple text runs, each holding a
- * part of the complete text. When replacing all text using the setText method on XSLFTextShape, the formatting might
- * get lost. So instead, this function sets the text in the first text run of the first paragraph, while emptying all
- * other text runs in all other paragraphs.
- * @param textShape The shape that contains the text to be replaced.
- * @param newText The new text.
- */
- private def replaceMaintainingTextFormat(textShape: XSLFTextShape, newText: String) = {
- for {
- (paragraph, paragraphIndex) <- textShape.getTextParagraphs.zipWithIndex
- (run, runIndex) <- paragraph.getTextRuns.zipWithIndex
- } {
- if (paragraphIndex == 0 && runIndex == 0) {
- run.setText(newText)
- } else {
- run.setText("")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment