* </blockquote>
*/
public class XSSFRichTextString implements RichTextString {
- private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-F]{4})_");
+ private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-Fa-f]{4})_");
private CTRst st;
private StylesTable styles;
if(ctFont.sizeOfShadowArray() > 0) pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
if(ctFont.sizeOfStrikeArray() > 0) pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
}
-
+
/**
* Does this string have any explicit formatting applied, or is
* it just text in the default style?
*/
public boolean hasFormatting() {
+ //noinspection deprecation - for performance reasons!
CTRElt[] rs = st.getRArray();
if (rs == null || rs.length == 0) {
return false;
return utfDecode(st.getT());
}
StringBuilder buf = new StringBuilder();
+ //noinspection deprecation - for performance reasons!
for(CTRElt r : st.getRArray()){
buf.append(r.getT());
}
public XSSFFont getFontAtIndex( int index ) {
final ThemesTable themes = getThemesTable();
int pos = 0;
+ //noinspection deprecation - for performance reasons!
for(CTRElt r : st.getRArray()){
final int length = r.getT().length();
if(index >= pos && index < pos + length) {
protected void setStylesTableReference(StylesTable tbl){
styles = tbl;
if(st.sizeOfRArray() > 0) {
+ //noinspection deprecation - for performance reasons!
for (CTRElt r : st.getRArray()) {
CTRPrElt pr = r.getRPr();
if(pr != null && pr.sizeOfRFontArray() > 0){
TreeMap<Integer, CTRPrElt> getFormatMap(CTRst entry){
int length = 0;
TreeMap<Integer, CTRPrElt> formats = new TreeMap<Integer, CTRPrElt>();
+ //noinspection deprecation - for performance reasons!
for (CTRElt r : entry.getRArray()) {
String txt = r.getT();
CTRPrElt fmt = r.getRPr();
/**
* test that unicode representation_ xHHHH_ is properly processed
*/
- public void testUtfDecode() {
+ public void testUtfDecode() throws IOException {
CTRst st = CTRst.Factory.newInstance();
st.setT("abc_x000D_2ef_x000D_");
XSSFRichTextString rt = new XSSFRichTextString(st);
//_x000D_ is converted into carriage return
assertEquals("abc\r2ef\r", rt.getString());
-
+
+ // Test Lowercase case
+ CTRst st2 = CTRst.Factory.newInstance();
+ st2.setT("abc_x000d_2ef_x000d_");
+ XSSFRichTextString rt2 = new XSSFRichTextString(st2);
+ assertEquals("abc\r2ef\r", rt2.getString());
}
public void testApplyFont_lowlevel(){
public void testLineBreaks_bug48877() throws IOException{
XSSFFont font = new XSSFFont();
+ //noinspection deprecation
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 14);
XSSFRichTextString str;
str.applyFont(0, 4, font);
t1 = str.getCTRst().getRArray(0).xgetT();
t2 = str.getCTRst().getRArray(1).xgetT();
- // YK: don't know why, but XmlBeans converts leading tab characters to spaces
- //assertEquals("<xml-fragment>Tab\t</xml-fragment>", t1.xmlText());
+ assertEquals("<xml-fragment xml:space=\"preserve\">Tab\t</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">separated\n</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("\n\n\nNew Line\n\n");
assertEquals("<xml-fragment xml:space=\"preserve\">\n\n</xml-fragment>", t3.xmlText());
}
-
- @Test
public void testBug56511() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
for (Sheet sheet : wb) {
}
}
- @Test
public void testBug56511_values() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
Sheet sheet = wb.getSheetAt(0);
assertEquals(font, rts.getFontAtIndex(s2-1));
assertEquals("<xml-fragment/>", rts.getFontAtIndex(s3-1).toString());
}
+
+ public void test60289UtfDecode() throws IOException {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("60289.xlsx");
+ assertEquals("Rich Text\r\nTest", wb.getSheetAt(0).getRow(1).getCell(1).getRichStringCellValue().getString());
+ wb.close();
+ }
}