/** * Append new text to this text run * * @param text the text to append */ public void append(String text){ append(text, null); }
/** * Append new text to this text run * * @param text the text to append */ public void append(String text){ append(text, null); }
/** * Append new text to this text run * * @param text the text to append */ public void append(String text){ append(text, null); }
String str = "AZERTY<em>ZA</em> QWERTY OK <em>NE</em>NO"; //replace word in string which is preceded by <\em> to word:font eg. ZA:font str = str.replaceAll("(\\w+)(?=\\<\\/em\\>)", "$1:font"); // After replace :AZERTY<em>ZA:font</em> QWERTY OK <em>NE:font</em>NO String[] parts = str.split("(<\\/?em>)"); // After split : [AZERTY, ZA:font, QWERTY OK , NE:font, NO] XSSFRichTextString xssfrt = new XSSFRichTextString(); for(String s:parts){ //set font according to replace string if(s.contains(":")){ String[] subParts = s.split(":"); xssfrt.append(subParts[0], /**check the subParts[0] and set the font***/ ); }else{ xssfrt.append(s); } } }
XSSFRichTextString rt1 = new XSSFRichTextString("Apache POI is"); rt1.applyFont(plainArial); XSSFRichTextString rt2 = new XSSFRichTextString(" great!"); rt2.applyFont(boldArial); String text = rt2.getString(); cell1.setCellValue(rt1.append(text, boldArial));
rt.append(" Jumped over the lazy dog", font3);