Guest User

Untitled

a guest
Sep 22nd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.90 KB | None | 0 0
  1.   /**
  2.    * Each text shape can contain multiple paragraphs, and each paragraph can have multiple text runs, each holding a
  3.    * part of the complete text. When replacing all text using the setText method on XSLFTextShape, the formatting might
  4.    * get lost. So instead, this function sets the text in the first text run of the first paragraph, while emptying all
  5.    * other text runs in all other paragraphs.
  6.    * @param textShape The shape that contains the text to be replaced.
  7.    * @param newText The new text.
  8.    */
  9.   private def replaceMaintainingTextFormat(textShape: XSLFTextShape, newText: String) = {
  10.     for {
  11.       (paragraph, paragraphIndex) <- textShape.getTextParagraphs.zipWithIndex
  12.       (run, runIndex) <- paragraph.getTextRuns.zipWithIndex
  13.     } {
  14.       if (paragraphIndex == 0 && runIndex == 0) {
  15.         run.setText(newText)
  16.       } else {
  17.         run.setText("")
  18.       }
  19.     }
  20.   }
Advertisement
Add Comment
Please, Sign In to add comment