/** * Add an entry to this Shared String table (a new value is appended to the end). * * <p> * If the Shared String table already contains this <code>CTRst</code> bean, its index is returned. * Otherwise a new entry is aded. * </p> * * @param st the entry to add * @return index the index of added entry * @deprecated use <code>addSharedStringItem(RichTextString string)</code> instead */ @Removal(version = "4.2") //make private in 4.2 public int addEntry(CTRst st) { String s = xmlText(st); count++; if (stmap.containsKey(s)) { return stmap.get(s); } uniqueCount++; //create a CTRst bean attached to this SstDocument and copy the argument CTRst into it CTRst newSt = _sstDoc.getSst().addNewSi(); newSt.set(st); int idx = strings.size(); stmap.put(s, idx); strings.add(newSt); return idx; }
/** * Applies a font to the specified characters of a string. * * @param startIndex The start index to apply the font to (inclusive) * @param endIndex The end index to apply to font to (exclusive) * @param font The index of the font to use. */ public void applyFont(int startIndex, int endIndex, Font font) { if (startIndex > endIndex) throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex); if (startIndex < 0 || endIndex > length()) throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex); if (startIndex == endIndex) return; if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> st.addNewR().setT(st.getT()); st.unsetT(); } String text = getString(); XSSFFont xssfFont = (XSSFFont)font; TreeMap<Integer, CTRPrElt> formats = getFormatMap(st); CTRPrElt fmt = CTRPrElt.Factory.newInstance(); setRunAttributes(xssfFont.getCTFont(), fmt); applyFont(formats, startIndex, endIndex, fmt); CTRst newSt = buildCTRst(text, formats); st.set(newSt); }
/** * Add an entry to this Shared String table (a new value is appened to the end). * * <p> * If the Shared String table already contains this <code>CTRst</code> bean, its index is returned. * Otherwise a new entry is aded. * </p> * * @param st the entry to add * @return index the index of added entry */ public int addEntry(CTRst st) { String s = getKey(st); count++; if (stmap.containsKey(s)) { return stmap.get(s); } uniqueCount++; //create a CTRst bean attached to this SstDocument and copy the argument CTRst into it CTRst newSt = _sstDoc.getSst().addNewSi(); newSt.set(st); int idx = strings.size(); stmap.put(s, idx); strings.add(newSt); return idx; } /**
/** * Add an entry to this Shared String table (a new value is appended to the end). * * <p> * If the Shared String table already contains this <code>CTRst</code> bean, its index is returned. * Otherwise a new entry is aded. * </p> * * @param st the entry to add * @return index the index of added entry * @deprecated use <code>addSharedStringItem(RichTextString string)</code> instead */ @Removal(version = "4.2") //make private in 4.2 public int addEntry(CTRst st) { String s = xmlText(st); count++; if (stmap.containsKey(s)) { return stmap.get(s); } uniqueCount++; //create a CTRst bean attached to this SstDocument and copy the argument CTRst into it CTRst newSt = _sstDoc.getSst().addNewSi(); newSt.set(st); int idx = strings.size(); stmap.put(s, idx); strings.add(newSt); return idx; }
/** * Applies a font to the specified characters of a string. * * @param startIndex The start index to apply the font to (inclusive) * @param endIndex The end index to apply to font to (exclusive) * @param font The index of the font to use. */ public void applyFont(int startIndex, int endIndex, Font font) { if (startIndex > endIndex) throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex); if (startIndex < 0 || endIndex > length()) throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex); if (startIndex == endIndex) return; if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> st.addNewR().setT(st.getT()); st.unsetT(); } String text = getString(); XSSFFont xssfFont = (XSSFFont)font; TreeMap<Integer, CTRPrElt> formats = getFormatMap(st); CTRPrElt fmt = CTRPrElt.Factory.newInstance(); setRunAttributes(xssfFont.getCTFont(), fmt); applyFont(formats, startIndex, endIndex, fmt); CTRst newSt = buildCTRst(text, formats); st.set(newSt); }
/** * Applies a font to the specified characters of a string. * * @param startIndex The start index to apply the font to (inclusive) * @param endIndex The end index to apply to font to (exclusive) * @param font The index of the font to use. */ public void applyFont(int startIndex, int endIndex, Font font) { if (startIndex > endIndex) throw new IllegalArgumentException("Start index must be less than end index."); if (startIndex < 0 || endIndex > length()) throw new IllegalArgumentException("Start and end index not in range."); if (startIndex == endIndex) return; if(st.sizeOfRArray() == 0 && st.isSetT()) { //convert <t>string</t> into a text run: <r><t>string</t></r> st.addNewR().setT(st.getT()); st.unsetT(); } String text = getString(); XSSFFont xssfFont = (XSSFFont)font; TreeMap<Integer, CTRPrElt> formats = getFormatMap(st); CTRPrElt fmt = CTRPrElt.Factory.newInstance(); setRunAttributes(xssfFont.getCTFont(), fmt); applyFont(formats, startIndex, endIndex, fmt); CTRst newSt = buildCTRst(text, formats); st.set(newSt); }