Browse Source

Bug 64750: Do not use CTDataValidations.getCount(), instead only rely on getDataValidationArray

Field "count" seems to be optional according
to the schema, so by using only the array
Apache POI can read data validations from
workbooks that do not populate the
"count" field properly.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885011 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_0_0
Dominik Stadler 3 years ago
parent
commit
685af351d1

+ 2
- 2
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java View File

@@ -80,7 +80,6 @@ import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
import org.apache.poi.util.Units;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
@@ -4011,7 +4010,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
public List<XSSFDataValidation> getDataValidations() {
List<XSSFDataValidation> xssfValidations = new ArrayList<>();
CTDataValidations dataValidations = this.worksheet.getDataValidations();
if( dataValidations!=null && dataValidations.getCount() > 0 ) {
if (dataValidations != null) {
for (CTDataValidation ctDataValidation : dataValidations.getDataValidationArray()) {
CellRangeAddressList addressList = new CellRangeAddressList();

@@ -4031,6 +4030,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
xssfValidations.add(xssfDataValidation);
}
}

return xssfValidations;
}


+ 8
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java View File

@@ -3661,4 +3661,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(CellType.NUMERIC, value.getCellType());
assertEquals(1, value.getNumberValue(), 0.01);
}

@Test
public void test64750() throws IOException {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("64750.xlsx")) {
Sheet sheet = wb.getSheet("Sheet1");
assertEquals(1, sheet.getDataValidations().size());
}
}
}

BIN
test-data/spreadsheet/64750.xlsx View File


Loading…
Cancel
Save