mirror of https://github.com/apache/poi.git
Small tweaks for data validation (bug 44953)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@682230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ec23808c6
commit
8743c33bd8
|
@ -37,22 +37,22 @@ public class DVConstraint {
|
||||||
private ValidationType() {
|
private ValidationType() {
|
||||||
// no instances of this class
|
// no instances of this class
|
||||||
}
|
}
|
||||||
/** 'Any value' type - value not restricted */
|
/** 'Any value' type - value not restricted */
|
||||||
public static final int ANY = 0x00;
|
public static final int ANY = 0x00;
|
||||||
/** Integer ('Whole number') type */
|
/** Integer ('Whole number') type */
|
||||||
public static final int INTEGER = 0x01;
|
public static final int INTEGER = 0x01;
|
||||||
/** Decimal type */
|
/** Decimal type */
|
||||||
public static final int DECIMAL = 0x02;
|
public static final int DECIMAL = 0x02;
|
||||||
/** List type ( combo box type ) */
|
/** List type ( combo box type ) */
|
||||||
public static final int LIST = 0x03;
|
public static final int LIST = 0x03;
|
||||||
/** Date type */
|
/** Date type */
|
||||||
public static final int DATE = 0x04;
|
public static final int DATE = 0x04;
|
||||||
/** Time type */
|
/** Time type */
|
||||||
public static final int TIME = 0x05;
|
public static final int TIME = 0x05;
|
||||||
/** String length type */
|
/** String length type */
|
||||||
public static final int TEXT_LENGTH = 0x06;
|
public static final int TEXT_LENGTH = 0x06;
|
||||||
/** Formula ( 'Custom' ) type */
|
/** Formula ( 'Custom' ) type */
|
||||||
public static final int FORMULA = 0x07;
|
public static final int FORMULA = 0x07;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Condition operator enum
|
* Condition operator enum
|
||||||
|
@ -312,7 +312,7 @@ public class DVConstraint {
|
||||||
return new Double(HSSFDateUtil.getExcelDate(dateVal));
|
return new Double(HSSFDateUtil.getExcelDate(dateVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DVConstraint createFormulaConstraint(String formula) {
|
public static DVConstraint createCustomFormulaConstraint(String formula) {
|
||||||
if (formula == null) {
|
if (formula == null) {
|
||||||
throw new IllegalArgumentException("formula must be supplied");
|
throw new IllegalArgumentException("formula must be supplied");
|
||||||
}
|
}
|
||||||
|
@ -329,8 +329,8 @@ public class DVConstraint {
|
||||||
formula1 = createListFormula(workbook);
|
formula1 = createListFormula(workbook);
|
||||||
formula2 = Ptg.EMPTY_PTG_ARRAY;
|
formula2 = Ptg.EMPTY_PTG_ARRAY;
|
||||||
} else {
|
} else {
|
||||||
formula1 = convertDoubleFormula(_formula1, _value1, workbook);
|
formula1 = convertDoubleFormula(_formula1, _value1, workbook);
|
||||||
formula2 = convertDoubleFormula(_formula2, _value2, workbook);
|
formula2 = convertDoubleFormula(_formula2, _value2, workbook);
|
||||||
}
|
}
|
||||||
return new FormulaPair(formula1, formula2);
|
return new FormulaPair(formula1, formula2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,11 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
public final class TestDataValidation extends TestCase {
|
public final class TestDataValidation extends TestCase {
|
||||||
|
|
||||||
/** Convenient access to ERROR_STYLE constants */
|
/** Convenient access to ERROR_STYLE constants */
|
||||||
private static final HSSFDataValidation.ErrorStyle ES = null;
|
/*package*/ static final HSSFDataValidation.ErrorStyle ES = null;
|
||||||
/** Convenient access to OPERATOR constants */
|
/** Convenient access to OPERATOR constants */
|
||||||
private static final DVConstraint.ValidationType VT = null;
|
/*package*/ static final DVConstraint.ValidationType VT = null;
|
||||||
/** Convenient access to OPERATOR constants */
|
/** Convenient access to OPERATOR constants */
|
||||||
private static final DVConstraint.OperatorType OP = null;
|
/*package*/ static final DVConstraint.OperatorType OP = null;
|
||||||
|
|
||||||
private static void log(String msg) {
|
private static void log(String msg) {
|
||||||
if (false) { // successful tests should be silent
|
if (false) { // successful tests should be silent
|
||||||
|
@ -130,7 +130,7 @@ public final class TestDataValidation extends TestCase {
|
||||||
return DVConstraint.createDateConstraint(operatorType, firstFormula, secondFormula, null);
|
return DVConstraint.createDateConstraint(operatorType, firstFormula, secondFormula, null);
|
||||||
}
|
}
|
||||||
if (_validationType == VT.FORMULA) {
|
if (_validationType == VT.FORMULA) {
|
||||||
return DVConstraint.createFormulaConstraint(firstFormula);
|
return DVConstraint.createCustomFormulaConstraint(firstFormula);
|
||||||
}
|
}
|
||||||
return DVConstraint.createNumericConstraint(_validationType, operatorType, firstFormula, secondFormula);
|
return DVConstraint.createNumericConstraint(_validationType, operatorType, firstFormula, secondFormula);
|
||||||
}
|
}
|
||||||
|
@ -573,23 +573,8 @@ public final class TestDataValidation extends TestCase {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("dvEmpty.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("dvEmpty.xls");
|
||||||
int dvRow = 0;
|
int dvRow = 0;
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
sheet.createRow(dvRow).createCell((short)0);
|
DVConstraint dc = DVConstraint.createNumericConstraint(VT.INTEGER, OP.EQUAL, "42", null);
|
||||||
DVConstraint dc = DVConstraint.createNumericConstraint(VT.INTEGER, OP.EQUAL, "402", null);
|
HSSFDataValidation dv = new HSSFDataValidation(new CellRangeAddressList(dvRow, dvRow, 0, 0), dc);
|
||||||
HSSFDataValidation dv = new HSSFDataValidation(new CellRangeAddressList(dvRow, 0, dvRow, 0), dc);
|
|
||||||
|
|
||||||
|
|
||||||
dv.setEmptyCellAllowed(false);
|
|
||||||
dv.setErrorStyle(ES.STOP);
|
|
||||||
dv.setShowPromptBox(true);
|
|
||||||
dv.createErrorBox("Error", "The value is wrong");
|
|
||||||
dv.setSuppressDropDownArrow(true);
|
|
||||||
|
|
||||||
// sheet.addValidationData(dv);
|
|
||||||
|
|
||||||
|
|
||||||
dc = DVConstraint.createNumericConstraint(VT.INTEGER, OP.EQUAL, "42", null);
|
|
||||||
dv = new HSSFDataValidation(new CellRangeAddressList(0, 0, 0, 0), dc);
|
|
||||||
|
|
||||||
|
|
||||||
dv.setEmptyCellAllowed(false);
|
dv.setEmptyCellAllowed(false);
|
||||||
dv.setErrorStyle(ES.STOP);
|
dv.setErrorStyle(ES.STOP);
|
||||||
|
@ -599,8 +584,6 @@ public final class TestDataValidation extends TestCase {
|
||||||
|
|
||||||
sheet.addValidationData(dv);
|
sheet.addValidationData(dv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
|
@ -637,22 +620,9 @@ public final class TestDataValidation extends TestCase {
|
||||||
// and the DV records, Excel will not be able to open the workbook without error.
|
// and the DV records, Excel will not be able to open the workbook without error.
|
||||||
|
|
||||||
if (nextSid == 0x0867) {
|
if (nextSid == 0x0867) {
|
||||||
throw new AssertionFailedError("Identified bug XXXX");
|
throw new AssertionFailedError("Identified bug 45519");
|
||||||
}
|
}
|
||||||
assertEquals(DVRecord.sid, nextSid);
|
assertEquals(DVRecord.sid, nextSid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
File tempDir = new File("c:/josh/temp");
|
|
||||||
File generatedFile = new File(tempDir, "dvEx2.xls");
|
|
||||||
try {
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(generatedFile);
|
|
||||||
wb.write(fileOut);
|
|
||||||
fileOut.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private int findIndex(byte[] largeData, byte[] searchPattern) {
|
private int findIndex(byte[] largeData, byte[] searchPattern) {
|
||||||
byte firstByte = searchPattern[0];
|
byte firstByte = searchPattern[0];
|
||||||
|
|
Loading…
Reference in New Issue