use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.
the class TestXSSFRichTextString method testUtfDecode.
/**
* test that unicode representation_ xHHHH_ is properly processed
*/
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());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.
the class SharedStringsTable method readFrom.
/**
* Read this shared strings table from an XML file.
*
* @param is The input stream containing the XML document.
* @throws IOException if an error occurs while reading.
*/
public void readFrom(InputStream is) throws IOException {
try {
int cnt = 0;
_sstDoc = SstDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
CTSst sst = _sstDoc.getSst();
count = (int) sst.getCount();
uniqueCount = (int) sst.getUniqueCount();
for (CTRst st : sst.getSiArray()) {
stmap.put(getKey(st), cnt);
strings.add(st);
cnt++;
}
} catch (XmlException e) {
throw new IOException("unable to parse shared strings table", e);
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.
the class XSSFRichTextString method applyFont.
/**
* 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);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.
the class XSSFRichTextString method buildCTRst.
CTRst buildCTRst(String text, TreeMap<Integer, CTRPrElt> formats) {
if (text.length() != formats.lastKey()) {
throw new IllegalArgumentException("Text length was " + text.length() + " but the last format index was " + formats.lastKey());
}
CTRst stf = CTRst.Factory.newInstance();
int runStartIdx = 0;
for (Map.Entry<Integer, CTRPrElt> me : formats.entrySet()) {
int runEndIdx = me.getKey();
CTRElt run = stf.addNewR();
String fragment = text.substring(runStartIdx, runEndIdx);
run.setT(fragment);
preserveSpaces(run.xgetT());
CTRPrElt fmt = me.getValue();
if (fmt != null) {
run.setRPr(fmt);
}
runStartIdx = runEndIdx;
}
return stf;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.
the class TestReadOnlySharedStringsTable method testParse.
public void testParse() throws Exception {
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
List<PackagePart> parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml"));
assertEquals(1, parts.size());
SharedStringsTable stbl = new SharedStringsTable(parts.get(0));
ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0));
assertEquals(stbl.getCount(), rtbl.getCount());
assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount());
assertEquals(stbl.getItems().size(), stbl.getUniqueCount());
assertEquals(rtbl.getItems().size(), rtbl.getUniqueCount());
for (int i = 0; i < stbl.getUniqueCount(); i++) {
CTRst i1 = stbl.getEntryAt(i);
String i2 = rtbl.getEntryAt(i);
assertEquals(i1.getT(), i2);
}
}
Aggregations