StringBuilder out = new StringBuilder();
List<Integer> levelCount = new ArrayList<>(MAX_LEVELS); // maximum 9
// levels
- XSSFTextParagraph p = null;
-
// initialise the levelCount array - this maintains a record of the
// numbering to be used at each level
for (int k = 0; k < MAX_LEVELS; k++) {
if (out.length() > 0) {
out.append('\n');
}
- p = _paragraphs.get(i);
+ XSSFTextParagraph p = _paragraphs.get(i);
if (p.isBullet() && p.getText().length() > 0) {
*
*/
private int processAutoNumGroup(int index, int level, List<Integer> levelCount, StringBuilder out) {
- XSSFTextParagraph p = null;
- XSSFTextParagraph nextp = null;
- ListAutoNumber scheme, nextScheme;
- int startAt, nextStartAt;
-
- p = _paragraphs.get(index);
+ XSSFTextParagraph p = _paragraphs.get(index);
// The rules for generating the auto numbers are as follows. If the
// following paragraph is also
// first auto-number paragraph so initialise to 1 or the bullets startAt
// if present
- startAt = p.getBulletAutoNumberStart();
- scheme = p.getBulletAutoNumberScheme();
+ int startAt = p.getBulletAutoNumberStart();
+ ListAutoNumber scheme = p.getBulletAutoNumberScheme();
if (levelCount.get(level) == 0) {
levelCount.set(level, startAt == 0 ? 1 : startAt);
}
out.append(p.getText());
}
while (true) {
- nextp = (index + 1) == _paragraphs.size() ? null : _paragraphs.get(index + 1);
+ XSSFTextParagraph nextp = (index + 1) == _paragraphs.size() ? null : _paragraphs.get(index + 1);
if (nextp == null) {
break; // out of paragraphs
}
} else if (nextp.getLevel() < level) {
break; // changed level
}
- nextScheme = nextp.getBulletAutoNumberScheme();
- nextStartAt = nextp.getBulletAutoNumberStart();
+ ListAutoNumber nextScheme = nextp.getBulletAutoNumberScheme();
+ int nextStartAt = nextp.getBulletAutoNumberStart();
if (nextScheme == scheme && nextStartAt == startAt) {
// bullet is valid, so increment i
public void testCreate() {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
CTRst st = rt.getCTRst();
assertTrue(st.isSetT());
assertEquals("Apache POI", st.getT());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
rt.append(" is cool stuff");
assertEquals(2, st.sizeOfRArray());
assertFalse(st.isSetT());
assertEquals("Apache POI is cool stuff", rt.getString());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
}
public void testEmpty() {
rt.append("89");
assertEquals("123456789", rt.getString());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
XSSFFont font1 = new XSSFFont();
font1.setBold(true);
rt.applyFont(2, 5, font1);
- assertEquals(true, rt.hasFormatting());
+ assertTrue(rt.hasFormatting());
assertEquals(4, rt.numFormattingRuns());
assertEquals(0, rt.getIndexOfFormattingRun(0));
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
rt.clearFormatting();
assertTrue(st.isSetT());
assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
XSSFFont font = new XSSFFont();
font.setBold(true);
rt.applyFont(7, 10, font);
assertEquals(2, rt.numFormattingRuns());
- assertEquals(true, rt.hasFormatting());
+ assertTrue(rt.hasFormatting());
rt.clearFormatting();
assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns());
- assertEquals(false, rt.hasFormatting());
+ assertFalse(rt.hasFormatting());
}
public void testGetFonts() {
/**
* test that unicode representation_ xHHHH_ is properly processed
*/
- public void testUtfDecode() throws IOException {
+ public void testUtfDecode() {
CTRst st = CTRst.Factory.newInstance();
st.setT("abc_x000D_2ef_x000D_");
XSSFRichTextString rt = new XSSFRichTextString(st);
assertEquals(" Software Foundation", str.getCTRst().getRArray(1).getT());
}
- public void testLineBreaks_bug48877() throws IOException{
+ public void testLineBreaks_bug48877() {
XSSFFont font = new XSSFFont();
font.setBold(true);
assertEquals("<xml-fragment xml:space=\"preserve\">\n\n</xml-fragment>", t3.xmlText());
}
- public void testBug56511() {
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
- for (Sheet sheet : wb) {
- int lastRow = sheet.getLastRowNum();
- for (int rowIdx = sheet.getFirstRowNum(); rowIdx <= lastRow; rowIdx++) {
- Row row = sheet.getRow(rowIdx);
- if(row != null) {
- int lastCell = row.getLastCellNum();
-
- for (int cellIdx = row.getFirstCellNum(); cellIdx <= lastCell; cellIdx++) {
-
- Cell cell = row.getCell(cellIdx);
- if (cell != null) {
- //System.out.println("row " + rowIdx + " column " + cellIdx + ": " + cell.getCellType() + ": " + cell.toString());
-
- XSSFRichTextString richText = (XSSFRichTextString) cell.getRichStringCellValue();
- int anzFormattingRuns = richText.numFormattingRuns();
- for (int run = 0; run < anzFormattingRuns; run++) {
- /*XSSFFont font =*/ richText.getFontOfFormattingRun(run);
- //System.out.println(" run " + run
- // + " font " + (font == null ? "<null>" : font.getFontName()));
+ public void testBug56511() throws IOException {
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx")) {
+ for (Sheet sheet : wb) {
+ int lastRow = sheet.getLastRowNum();
+ for (int rowIdx = sheet.getFirstRowNum(); rowIdx <= lastRow; rowIdx++) {
+ Row row = sheet.getRow(rowIdx);
+ if (row != null) {
+ int lastCell = row.getLastCellNum();
+
+ for (int cellIdx = row.getFirstCellNum(); cellIdx <= lastCell; cellIdx++) {
+
+ Cell cell = row.getCell(cellIdx);
+ if (cell != null) {
+ //System.out.println("row " + rowIdx + " column " + cellIdx + ": " + cell.getCellType() + ": " + cell.toString());
+
+ XSSFRichTextString richText = (XSSFRichTextString) cell.getRichStringCellValue();
+ int anzFormattingRuns = richText.numFormattingRuns();
+ for (int run = 0; run < anzFormattingRuns; run++) {
+ /*XSSFFont font =*/ richText.getFontOfFormattingRun(run);
+ //System.out.println(" run " + run
+ // + " font " + (font == null ? "<null>" : font.getFontName()));
+ }
}
}
}
}
}
- public void testBug56511_values() {
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
- Sheet sheet = wb.getSheetAt(0);
- Row row = sheet.getRow(0);
+ public void testBug56511_values() throws IOException {
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx")) {
+ Sheet sheet = wb.getSheetAt(0);
+ Row row = sheet.getRow(0);
- // verify the values to ensure future changes keep the returned information equal
- XSSFRichTextString rt = (XSSFRichTextString) row.getCell(0).getRichStringCellValue();
- assertEquals(0, rt.numFormattingRuns());
- assertNull(rt.getFontOfFormattingRun(0));
- assertEquals(-1, rt.getLengthOfFormattingRun(0));
-
- rt = (XSSFRichTextString) row.getCell(1).getRichStringCellValue();
- assertEquals(0, row.getCell(1).getRichStringCellValue().numFormattingRuns());
- assertNull(rt.getFontOfFormattingRun(1));
- assertEquals(-1, rt.getLengthOfFormattingRun(1));
-
- rt = (XSSFRichTextString) row.getCell(2).getRichStringCellValue();
- assertEquals(2, rt.numFormattingRuns());
- assertNotNull(rt.getFontOfFormattingRun(0));
- assertEquals(4, rt.getLengthOfFormattingRun(0));
-
- assertNotNull(rt.getFontOfFormattingRun(1));
- assertEquals(9, rt.getLengthOfFormattingRun(1));
+ // verify the values to ensure future changes keep the returned information equal
+ XSSFRichTextString rt = (XSSFRichTextString) row.getCell(0).getRichStringCellValue();
+ assertEquals(0, rt.numFormattingRuns());
+ assertNull(rt.getFontOfFormattingRun(0));
+ assertEquals(-1, rt.getLengthOfFormattingRun(0));
- assertNull(rt.getFontOfFormattingRun(2));
-
- rt = (XSSFRichTextString) row.getCell(3).getRichStringCellValue();
- assertEquals(3, rt.numFormattingRuns());
- assertNull(rt.getFontOfFormattingRun(0));
- assertEquals(1, rt.getLengthOfFormattingRun(0));
-
- assertNotNull(rt.getFontOfFormattingRun(1));
- assertEquals(3, rt.getLengthOfFormattingRun(1));
-
- assertNotNull(rt.getFontOfFormattingRun(2));
- assertEquals(9, rt.getLengthOfFormattingRun(2));
+ rt = (XSSFRichTextString) row.getCell(1).getRichStringCellValue();
+ assertEquals(0, row.getCell(1).getRichStringCellValue().numFormattingRuns());
+ assertNull(rt.getFontOfFormattingRun(1));
+ assertEquals(-1, rt.getLengthOfFormattingRun(1));
+
+ rt = (XSSFRichTextString) row.getCell(2).getRichStringCellValue();
+ assertEquals(2, rt.numFormattingRuns());
+ assertNotNull(rt.getFontOfFormattingRun(0));
+ assertEquals(4, rt.getLengthOfFormattingRun(0));
+
+ assertNotNull(rt.getFontOfFormattingRun(1));
+ assertEquals(9, rt.getLengthOfFormattingRun(1));
+
+ assertNull(rt.getFontOfFormattingRun(2));
+
+ rt = (XSSFRichTextString) row.getCell(3).getRichStringCellValue();
+ assertEquals(3, rt.numFormattingRuns());
+ assertNull(rt.getFontOfFormattingRun(0));
+ assertEquals(1, rt.getLengthOfFormattingRun(0));
+
+ assertNotNull(rt.getFontOfFormattingRun(1));
+ assertEquals(3, rt.getLengthOfFormattingRun(1));
+
+ assertNotNull(rt.getFontOfFormattingRun(2));
+ assertEquals(9, rt.getLengthOfFormattingRun(2));
+ }
}
public void testToString() {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertNotNull(rt.toString());
-
- // TODO: normally toString() should never return null, should we adjust this?
+
rt = new XSSFRichTextString();
- assertNull(rt.toString());
+ assertEquals("", rt.toString());
}
public void test59008Font() {