View | Details | Raw Unified | Return to bug 59719
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationConstraint.java (-2 / +13 lines)
Lines 69-74 Link Here
69
		validate();
69
		validate();
70
	}
70
	}
71
71
72
	/**
73
	 * This is the constructor called using the OOXML raw data.  Excel overloads formula1 to also encode explicit value lists,
74
	 * so this constructor has to check for and parse that syntax.
75
	 * @param validationType
76
	 * @param operator
77
	 * @param formula1
78
	 * @param formula2
79
	 */
72
	public XSSFDataValidationConstraint(int validationType, int operator,String formula1, String formula2) {
80
	public XSSFDataValidationConstraint(int validationType, int operator,String formula1, String formula2) {
73
		super();
81
		super();
74
		setFormula1(formula1);
82
		setFormula1(formula1);
Lines 130-137 Link Here
130
	 */
138
	 */
131
	public void setExplicitListValues(String[] explicitListValues) {
139
	public void setExplicitListValues(String[] explicitListValues) {
132
		this.explicitListOfValues = explicitListValues;
140
		this.explicitListOfValues = explicitListValues;
141
		
142
	    // for OOXML we need to set formula1 to the quoted csv list of values (doesn't appear documented, but that's where Excel puts its lists)
143
        // further, Excel has no escaping for commas in explicit lists, so we don't need to worry about that.
133
		if( explicitListOfValues!=null && explicitListOfValues.length > 0 ) {
144
		if( explicitListOfValues!=null && explicitListOfValues.length > 0 ) {
134
			StringBuilder builder = new StringBuilder("\"");
145
			StringBuilder builder = new StringBuilder(QUOTE);
135
			for (int i = 0; i < explicitListValues.length; i++) {
146
			for (int i = 0; i < explicitListValues.length; i++) {
136
				String string = explicitListValues[i];
147
				String string = explicitListValues[i];
137
				if( builder.length() > 1) {
148
				if( builder.length() > 1) {
Lines 139-145 Link Here
139
				}
150
				}
140
				builder.append(string);
151
				builder.append(string);
141
			}
152
			}
142
			builder.append("\"");
153
			builder.append(QUOTE);
143
			setFormula1(builder.toString());			
154
			setFormula1(builder.toString());			
144
		}
155
		}
145
	}
156
	}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java (+3 lines)
Lines 43-48 Link Here
43
        String namedRange = "MyNamedRange";
43
        String namedRange = "MyNamedRange";
44
        constraint = new XSSFDataValidationConstraint(listType, ignoredType, namedRange, null);
44
        constraint = new XSSFDataValidationConstraint(listType, ignoredType, namedRange, null);
45
        assertNull(constraint.getExplicitListValues());
45
        assertNull(constraint.getExplicitListValues());
46
        
47
        constraint = new XSSFDataValidationConstraint(expected);
48
        assertEquals(literal.replace(" ", ""), constraint.getFormula1());
46
    }
49
    }
47
50
48
}        
51
}        

Return to bug 59719