diff options
author | Greg Woolsey <gwoolsey@apache.org> | 2017-11-16 01:22:52 +0000 |
---|---|---|
committer | Greg Woolsey <gwoolsey@apache.org> | 2017-11-16 01:22:52 +0000 |
commit | 83a143088737a09cb1167b909591049725f44bc5 (patch) | |
tree | bbd6b2fa1240f24ea8bc4ae3a98276ab604a4c18 /src/java | |
parent | 8caf25f718d218eaf90415bc8fd0066c85d3cf40 (diff) | |
download | poi-83a143088737a09cb1167b909591049725f44bc5.tar.gz poi-83a143088737a09cb1167b909591049725f44bc5.zip |
add Locale awareness to case insensitive conditional comparisons in formatting rule logic. Needed anyway, and removes forbidden API issues.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1815404 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java index 805763e38a..55a684d5cd 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java @@ -17,6 +17,8 @@ package org.apache.poi.ss.formula; +import java.text.CollationKey; +import java.text.Collator; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; @@ -49,6 +51,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; +import org.apache.poi.util.LocaleUtil; /** * Abstracted and cached version of a Conditional Format rule for use with a @@ -86,6 +89,9 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon private final String formula1; private final String formula2; private final String text; + // cached for performance, used with cell text comparisons, which are case insensitive and need to be Locale aware (contains, starts with, etc.) + private final String lowerText; + private final OperatorEnum operator; private final ConditionType type; // cached for performance, to avoid reading the XMLBean every time a conditionally formatted cell is rendered @@ -118,12 +124,16 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon this.regions = regions; formula1 = rule.getFormula1(); formula2 = rule.getFormula2(); + text = rule.getText(); + lowerText = text == null ? null : text.toLowerCase(LocaleUtil.getUserLocale()); + numberFormat = rule.getNumberFormat(); operator = OperatorEnum.values()[rule.getComparisonOperation()]; type = rule.getConditionType(); +// Excel uses the stored text representation from the XML apparently, in tests done so far decimalTextFormat = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); decimalTextFormat.setMaximumFractionDigits(340); // DecimalFormat.DOUBLE_FRACTION_DIGITS, which is default scoped } @@ -559,16 +569,16 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon return op.isValid(val, comp, null); case CONTAINS_TEXT: // implemented both by a cfRule "text" attribute and a formula. Use the text. - return cv.toString().toLowerCase().contains(text.toLowerCase()); + return text == null ? false : cv.toString().toLowerCase(LocaleUtil.getUserLocale()).contains(lowerText); case NOT_CONTAINS_TEXT: // implemented both by a cfRule "text" attribute and a formula. Use the text. - return ! cv.toString().toLowerCase().contains(text.toLowerCase()); + return text == null ? true : ! cv.toString().toLowerCase(LocaleUtil.getUserLocale()).contains(lowerText); case BEGINS_WITH: // implemented both by a cfRule "text" attribute and a formula. Use the text. - return cv.toString().toLowerCase().startsWith(text.toLowerCase()); + return cv.toString().toLowerCase(LocaleUtil.getUserLocale()).startsWith(lowerText); case ENDS_WITH: // implemented both by a cfRule "text" attribute and a formula. Use the text. - return cv.toString().toLowerCase().endsWith(text.toLowerCase()); + return cv.toString().toLowerCase(LocaleUtil.getUserLocale()).endsWith(lowerText); case CONTAINS_BLANKS: try { String v = cv.getString(); |