Copy DataValidation

Jan 18, 2011 at 4:53 PM
Edited Jan 18, 2011 at 4:56 PM

I am working on an Excel template where some of the cells use a drop-down list to validate the data.  I have used the examples I've found for copying Data Validation to a new cell range, and I run into a small problem.  Here's the code that I'm using:


HSSFSheet sheet1 = hssfworkbook.GetSheet("Sheet1");

HSSFSheet sheet2 = hssfworkbook.GetSheet("Sheet2");
HSSFRow row0 = sheet2.CreateRow(0);
HSSFCell cell0 = row0.CreateCell(4);

row0= sheet2.CreateRow(1);
cell0= row0.CreateCell(4);

row0= sheet2.CreateRow(2);
cell0= row0.CreateCell(4);

NPOI.HSSF.Util.CellRangeAddressList rangeList = new   NPOI.HSSF.Util.CellRangeAddressList();
rangeList.AddCellRangeAddress( new NPOI.HSSF.Util.CellRangeAddress(1,100,11,11));
DVConstraint dvconstraint = DVConstraint.CreateFormulaListConstraint("ValidBiologyStudyProtocols"); // A named range setup in the template
NPOI.HSSF.Util.HSSFDataValidation dataValidation = new
NPOI.HSSF.Util.HSSFDataValidation(rangeList, dvconstraint);


This all works correctly, up to the last line (sheet1.AddValidationData(dataValidation);).  On this line, I am unable to find the AddValidationData method anywhere in the NPOI system.  Is this a method that I need to build myself, or am I just missing some reference?

I have looked through the .dll using the Object Browser in Visual Studio and still cannot find a reference to this method.


Any help would be greatly appreciated.


Thanks - Josh