public void TestGetDataValidationsListFormula() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; List<IDataValidation> list = sheet.GetDataValidations(); Assert.AreEqual(0, list.Count); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint constraint = dataValidationHelper.CreateFormulaListConstraint("A2"); CellRangeAddressList AddressList = new CellRangeAddressList(0, 0, 0, 0); IDataValidation validation = dataValidationHelper.CreateValidation(constraint, AddressList); validation.SuppressDropDownArrow = (/*setter*/true); sheet.AddValidationData(validation); list = sheet.GetDataValidations(); // <-- works Assert.AreEqual(1, list.Count); HSSFDataValidation dv = list[(0)] as HSSFDataValidation; Assert.AreEqual(true, dv.SuppressDropDownArrow); DVConstraint c = dv.Constraint; Assert.AreEqual(ValidationType.LIST, c.GetValidationType()); Assert.AreEqual("A2", c.Formula1); Assert.AreEqual(null, c.Formula2); Assert.AreEqual(double.NaN, c.Value1); Assert.AreEqual(double.NaN, c.Value2); }
public void TestGetDataValidationsListExplicit() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; List<IDataValidation> list = sheet.GetDataValidations(); Assert.AreEqual(0, list.Count); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint constraint = dataValidationHelper.CreateExplicitListConstraint(new String[] { "aaa", "bbb", "ccc" }); CellRangeAddressList AddressList = new CellRangeAddressList(0, 0, 0, 0); IDataValidation validation = dataValidationHelper.CreateValidation(constraint, AddressList); validation.SuppressDropDownArrow = (/*setter*/true); sheet.AddValidationData(validation); list = sheet.GetDataValidations(); // <-- works Assert.AreEqual(1, list.Count); HSSFDataValidation dv = list[(0)] as HSSFDataValidation; Assert.AreEqual(true, dv.SuppressDropDownArrow); DVConstraint c = dv.Constraint; Assert.AreEqual(ValidationType.LIST, c.GetValidationType()); Assert.AreEqual(null, c.Formula1); Assert.AreEqual(null, c.Formula2); Assert.AreEqual(double.NaN, c.Value1); Assert.AreEqual(double.NaN, c.Value2); String[] values = c.ExplicitListValues; Assert.AreEqual(3, values.Length); Assert.AreEqual("aaa", values[0]); Assert.AreEqual("bbb", values[1]); Assert.AreEqual("ccc", values[2]); }
public void TestGetDataValidationsDecimal(){ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; List<IDataValidation> list = sheet.GetDataValidations(); Assert.AreEqual(0, list.Count); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint constraint = dataValidationHelper.CreateDecimalConstraint(OperatorType.BETWEEN, "=A2", "200"); CellRangeAddressList AddressList = new CellRangeAddressList(0, 0, 0, 0); IDataValidation validation = dataValidationHelper.CreateValidation(constraint, AddressList); sheet.AddValidationData(validation); list = sheet.GetDataValidations(); // <-- works Assert.AreEqual(1, list.Count); HSSFDataValidation dv = list[(0)] as HSSFDataValidation; DVConstraint c = dv.Constraint; Assert.AreEqual(ValidationType.DECIMAL, c.GetValidationType()); Assert.AreEqual(OperatorType.BETWEEN, c.Operator); Assert.AreEqual("A2", c.Formula1); Assert.AreEqual(null, c.Formula2); Assert.AreEqual(double.NaN, c.Value1); Assert.AreEqual(200, c.Value2); }
public void TestGetDataValidationsDate() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; List<IDataValidation> list = sheet.GetDataValidations(); Assert.AreEqual(0, list.Count); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint constraint = dataValidationHelper.CreateDateConstraint(OperatorType.EQUAL, "2014/10/25", null, null); CellRangeAddressList AddressList = new CellRangeAddressList(0, 0, 0, 0); IDataValidation validation = dataValidationHelper.CreateValidation(constraint, AddressList); sheet.AddValidationData(validation); list = sheet.GetDataValidations(); // <-- works Assert.AreEqual(1, list.Count); HSSFDataValidation dv = list[(0)] as HSSFDataValidation; DVConstraint c = dv.Constraint; Assert.AreEqual(ValidationType.DATE, c.GetValidationType()); Assert.AreEqual(OperatorType.EQUAL, c.Operator); Assert.AreEqual(null, c.Formula1); Assert.AreEqual(null, c.Formula2); Assert.AreEqual(DateUtil.GetExcelDate(DateUtil.ParseYYYYMMDDDate("2014/10/25")), c.Value1); Assert.AreEqual(double.NaN, c.Value2); }
public void TestGetDataValidationsFormula() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; List <IDataValidation> list = sheet.GetDataValidations(); Assert.AreEqual(0, list.Count); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint constraint = dataValidationHelper.CreateCustomConstraint("A2:A3"); CellRangeAddressList AddressList = new CellRangeAddressList(0, 0, 0, 0); IDataValidation validation = dataValidationHelper.CreateValidation(constraint, AddressList); sheet.AddValidationData(validation); list = sheet.GetDataValidations(); // <-- works Assert.AreEqual(1, list.Count); HSSFDataValidation dv = list[(0)] as HSSFDataValidation; DVConstraint c = dv.Constraint; Assert.AreEqual(ValidationType.FORMULA, c.GetValidationType()); Assert.AreEqual("A2:A3", c.Formula1); Assert.AreEqual(null, c.Formula2); Assert.AreEqual(double.NaN, c.Value1); Assert.AreEqual(double.NaN, c.Value2); }