// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
...
// Create named range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4");
// Add data validation as drop down list type
ExcelWorksheet xlsFirstTab = (ExcelWorksheet)workbook.easy_getSheetAt(0);
xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST,
DataValidator.OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
xlsFirstTab.easy_addDataValidator("B1:B10", DataValidator.VALIDATE_WHOLE_NUMBER,
DataValidator.OPERATOR_BETWEEN, "=4", "=100");
// Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
' Set sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
...
' Create named range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4")
' Add data validation as drop down list typeDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST, _
DataValidator.OPERATOR_EQUAL_TO, "=Range", "")
' Add data validation as whole number type
xlsFirstTab.easy_addDataValidator("B1:B10", DataValidator.VALIDATE_WHOLE_NUMBER, _
DataValidator.OPERATOR_BETWEEN, "=4", "=100")
' Create Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel data validation.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
...
// Create named range
xlsSecondTab->easy_addName_2("Range", "=Second tab!$A$1:$A$4");
// Add data validation as drop down list type
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
xlsFirstTab->easy_addDataValidator_3("A1:A10", DATAVALIDATOR_VALIDATE_LIST,
DATAVALIDATOR_OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
xlsFirstTab->easy_addDataValidator_3("B1:B10", DATAVALIDATOR_VALIDATE_WHOLE_NUMBER,
DATAVALIDATOR_OPERATOR_BETWEEN, "=4", "=100");
// Create Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Set sheet names
workbook->easy_getSheetAt(0)->setSheetName("First tab");
workbook->easy_getSheetAt(1)->setSheetName("Second tab");
...
// Create named range
xlsSecondTab->easy_addName("Range", "=Second tab!$A$1:$A$4");
// Add data validation as drop down list type
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
xlsFirstTab->easy_addDataValidator("A1:A10", DataValidator::VALIDATE_LIST,
DataValidator::OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
xlsFirstTab->easy_addDataValidator("B1:B10", DataValidator::VALIDATE_WHOLE_NUMBER,
DataValidator::OPERATOR_BETWEEN, "=4", "=100");
// Create Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
...
// Create named range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4");
// Add data validation as drop down list type
ExcelWorksheet xlsFirstTab = (ExcelWorksheet)workbook.easy_getSheetAt(0);
xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST,
DataValidator.OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
xlsFirstTab.easy_addDataValidator("B1:B10", DataValidator.VALIDATE_WHOLE_NUMBER,
DataValidator.OPERATOR_BETWEEN, "=4", "=100");
// Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
...
// Create named range
$xlsSecondTab->easy_addName_2("Range", "=Second tab!\$A\$1:\$A\$4");
// Add data validation as drop down list type
$xlsFirstTab = $workbook->easy_getSheetAt(0);
$xlsFirstTab->easy_addDataValidator_3("A1:A10", $DATAVALIDATOR_VALIDATE_LIST,
$DATAVALIDATOR_OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
$xlsFirstTab->easy_addDataValidator_3("B1:B10", $DATAVALIDATOR_VALIDATE_WHOLE_NUMBER,
$DATAVALIDATOR_OPERATOR_BETWEEN, "=4", "=100");
// Create Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel data validation.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
...
// Create a named area range
$xlsSecondTab->easy_addName("Range", "=Second tab!\$A\$1:\$A\$4");
// Add data validation as drop down list type
$xlsFirstTab = $workbook->easy_getSheetAt(0);
$xlsFirstTab->easy_addDataValidator("A1:A10", $DATAVALIDATOR_VALIDATE_LIST,
$DATAVALIDATOR_OPERATOR_EQUAL_TO, "=Range", "");
// Add data validation as whole number type
$xlsFirstTab->easy_addDataValidator("B1:B10", $DATAVALIDATOR_VALIDATE_WHOLE_NUMBER,
$DATAVALIDATOR_OPERATOR_BETWEEN, "=4", "=100");
// Export Excel file
$workbook->easy_WriteXLSXFileC:\Samples\Excel data validation.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
...
' Create named range
xlsSecondTab.easy_addName_2 "Range", "=Second tab!$A$1:$A$4"' Add data validation as drop down list type
set xlsFirstTab = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator_3 "A1:A10", DATAVALIDATOR_VALIDATE_LIST, _
DATAVALIDATOR_OPERATOR_EQUAL_TO, "=Range", ""' Add data validation as whole number type
xlsFirstTab.easy_addDataValidator_3 "B1:B10", DATAVALIDATOR_VALIDATE_WHOLE_NUMBER, _
DATAVALIDATOR_OPERATOR_BETWEEN, "=4", "=100"' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel data validation.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
...
' Create named range
xlsSecondTab.easy_addName_2 "Range", "=Second tab!$A$1:$A$4"' Add data validation as drop down list type
Set xlsFirstTab = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator_3 "A1:A10", _
DataValidator.DATAVALIDATOR_VALIDATE_LIST, _
DataValidator.DATAVALIDATOR_OPERATOR_EQUAL_TO, "=Range", ""' Add data validation as whole number type
xlsFirstTab.easy_addDataValidator_3 "B1:B10", _
DataValidator.DATAVALIDATOR_VALIDATE_WHOLE_NUMBER, _
DataValidator.DATAVALIDATOR_OPERATOR_BETWEEN, "=4", "=100"' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel data validation.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
...
' Create named range
xlsSecondTab.easy_addName_2 "Range", "=Second tab!$A$1:$A$4"' Add data validation as drop down list typeset xlsFirstTab = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator_3 "A1:A10", VALIDATE_LIST, _
OPERATOR_EQUAL_TO, "=Range", ""' Add data validation as whole number type
xlsFirstTab.easy_addDataValidator_3 "B1:B10", VALIDATE_WHOLE_NUMBER, _
OPERATOR_BETWEEN, "=4", "=100"' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel data validation.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")>
...
<!-- Create named range --><cfset xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4")><!-- Add data validation as drop down list type --><cfset xlsFirstTab = workbook.easy_getSheetAt(0)><cfset xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST,
DataValidator.OPERATOR_EQUAL_TO, "=Range", "")><!-- Add data validation as whole number type --><cfset xlsFirstTab.easy_addDataValidator("B1:B10", DataValidator.VALIDATE_WHOLE_NUMBER,
DataValidator.OPERATOR_BETWEEN, "=4", "=100")><!-- Create Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel data validation.xlsx")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
...
# Create a named area range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4")
# Add data validation as drop down list type
xlsFirstTab = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator("A1:A10", DataValidator.VALIDATE_LIST,
DataValidator.OPERATOR_EQUAL_TO, "=Range", "")
# Add data validation as whole number type
xlsFirstTab.easy_addDataValidator("B1:B10", DataValidator.VALIDATE_WHOLE_NUMBER,
DataValidator.OPERATOR_BETWEEN, "=4", "=100")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
...
# Create a named area range
xlsSecondTab.easy_addName("Range", "=Second tab!$A$1:$A$4")
# Add data validation as drop down list type
xlsFirstTab = workbook.easy_getSheetAt(0)
xlsFirstTab.easy_addDataValidator("A1:A10", gateway.jvm.DataValidator.VALIDATE_LIST,
gateway.jvm.DataValidator.OPERATOR_EQUAL_TO, "=Range", "")
# Add data validation as whole number type
xlsFirstTab.easy_addDataValidator("B1:B10", gateway.jvm.DataValidator.VALIDATE_WHOLE_NUMBER,
gateway.jvm.DataValidator.OPERATOR_BETWEEN, "=4", "=100")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel data validation.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an Excel file with data validation applied on cell ranges.
Data validation type
EasyXLS supports the following types of validation:
- Whole number - Decimal - Drop down list - Date - Time - Text length - Custom