aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-07-31 17:22:05 +0000
committerNick Burch <nick@apache.org>2015-07-31 17:22:05 +0000
commit402c4455998c138d48f4c60a282fefc6d585945b (patch)
tree8afe35e6fac5306c1baea43bfd5dde3949748915 /src/ooxml
parent7caf5eda4c642fcb8bdf223ff71f8539e8ffab7b (diff)
downloadpoi-402c4455998c138d48f4c60a282fefc6d585945b.tar.gz
poi-402c4455998c138d48f4c60a282fefc6d585945b.zip
Have XSSF rich test strings report if they have formatting applied or not, and fix them to only add the formatting child element when needed
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693632 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java3
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java23
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java3
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java11
4 files changed, 34 insertions, 6 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
index 32eab8dc6b..27317345cd 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
@@ -40,9 +40,6 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
* For performance reasons, this class keeps a cache of all previously calculated intermediate
* cell values. Be sure to call {@link #clearAllCachedResultValues()} if any workbook cells are changed between
* calls to evaluate~ methods on this class.
- *
- * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
- * @author Josh Micich
*/
public class XSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluatorProvider {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
index 13a1de914f..a7f9b3a8e3 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
@@ -203,8 +203,11 @@ public class XSSFRichTextString implements RichTextString {
CTRElt lt = st.addNewR();
lt.setT(text);
preserveSpaces(lt.xgetT());
- CTRPrElt pr = lt.addNewRPr();
- if(font != null) setRunAttributes(font.getCTFont(), pr);
+
+ if (font != null) {
+ CTRPrElt pr = lt.addNewRPr();
+ setRunAttributes(font.getCTFont(), pr);
+ }
}
/**
@@ -244,6 +247,22 @@ public class XSSFRichTextString implements RichTextString {
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() {
+ @SuppressWarnings("deprecation")
+ CTRElt[] rs = st.getRArray();
+ if (rs == null || rs.length == 0) {
+ return false;
+ }
+ for (CTRElt r : rs) {
+ if (r.isSetRPr()) return true;
+ }
+ return false;
+ }
/**
* Removes any formatting that may have been applied to the string.
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 0d62135d6e..153fc05d90 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -1629,7 +1629,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* </p>
* @return true if the date systems used in the workbook starts in 1904
*/
- protected boolean isDate1904(){
+ @Internal
+ public boolean isDate1904(){
CTWorkbookPr workbookPr = workbook.getWorkbookPr();
return workbookPr != null && workbookPr.getDate1904();
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
index 8edf1930e0..b5f0a19b4e 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
@@ -41,16 +41,19 @@ public final class TestXSSFRichTextString extends TestCase {
public void testCreate() {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString());
+ assertEquals(false, rt.hasFormatting());
CTRst st = rt.getCTRst();
assertTrue(st.isSetT());
assertEquals("Apache POI", st.getT());
+ assertEquals(false, 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());
}
public void testEmpty() {
@@ -67,11 +70,13 @@ public final class TestXSSFRichTextString extends TestCase {
rt.append("89");
assertEquals("123456789", rt.getString());
+ assertEquals(false, rt.hasFormatting());
XSSFFont font1 = new XSSFFont();
font1.setBold(true);
rt.applyFont(2, 5, font1);
+ assertEquals(true, rt.hasFormatting());
assertEquals(4, rt.numFormattingRuns());
assertEquals(0, rt.getIndexOfFormattingRun(0));
@@ -152,6 +157,7 @@ public final class TestXSSFRichTextString extends TestCase {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString());
+ assertEquals(false, rt.hasFormatting());
rt.clearFormatting();
@@ -159,15 +165,20 @@ public final class TestXSSFRichTextString extends TestCase {
assertTrue(st.isSetT());
assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns());
+ assertEquals(false, rt.hasFormatting());
XSSFFont font = new XSSFFont();
font.setBold(true);
rt.applyFont(7, 10, font);
assertEquals(2, rt.numFormattingRuns());
+ assertEquals(true, rt.hasFormatting());
+
rt.clearFormatting();
+
assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns());
+ assertEquals(false, rt.hasFormatting());
}
public void testGetFonts() {