コード例 #1
0
ファイル: TestXSSFDataValidation.cs プロジェクト: zzy092/npoi
        public void TestCreateMultipleRegionsValidation()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet                 sheet = wb.CreateSheet() as XSSFSheet;
                IDataValidationHelper     dataValidationHelper = sheet.GetDataValidationHelper();
                IDataValidationConstraint constraint           = dataValidationHelper.CreateExplicitListConstraint(new string[] { "A" });
                CellRangeAddressList      cellRangeAddressList = new CellRangeAddressList();
                cellRangeAddressList.AddCellRangeAddress(0, 0, 0, 0);
                cellRangeAddressList.AddCellRangeAddress(0, 1, 0, 1);
                cellRangeAddressList.AddCellRangeAddress(0, 2, 0, 2);
                XSSFDataValidation dataValidation = dataValidationHelper.CreateValidation(constraint, cellRangeAddressList) as XSSFDataValidation;
                sheet.AddValidationData(dataValidation);

                Assert.AreEqual(new CellRangeAddress(0, 0, 0, 0), sheet.GetDataValidations()[0].Regions.CellRangeAddresses[0]);
                Assert.AreEqual(new CellRangeAddress(0, 0, 1, 1), sheet.GetDataValidations()[0].Regions.CellRangeAddresses[1]);
                Assert.AreEqual(new CellRangeAddress(0, 0, 2, 2), sheet.GetDataValidations()[0].Regions.CellRangeAddresses[2]);
                Assert.AreEqual("A1 B1 C1", dataValidation.GetCTDataValidation().sqref);
            }
            finally
            {
                wb.Close();
            }
        }
コード例 #2
0
ファイル: TestXSSFDataValidation.cs プロジェクト: zzy092/npoi
        public void TestSetAllowBlankToTrue()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet sheet = wb.CreateSheet() as XSSFSheet;

                XSSFDataValidation validation = CreateValidation(sheet);
                validation.GetCTDataValidation().allowBlank = (/*setter*/ true);

                sheet.AddValidationData(validation);

                List <IDataValidation> dataValidations = sheet.GetDataValidations();
                Assert.AreEqual(true, (dataValidations[0] as XSSFDataValidation).GetCTDataValidation().allowBlank);
            }
            finally
            {
                wb.Close();
            }
        }