The sample demonstrates how to write validation into spreadsheet.
private void ExcelDocViewer( string fileName ) { try { System.Diagnostics.Process.Start(fileName); } catch{} } private void btnRun_Click(object sender, System.EventArgs e) { Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; sheet.Range["B2"].Text = "Input Number(3-6):"; CellRange rangeNumber = sheet.Range["B3"]; rangeNumber.DataValidation.CompareOperator = ValidationComparisonOperator.Between; rangeNumber.DataValidation.Formula1 = "3"; rangeNumber.DataValidation.Formula2 = "6"; rangeNumber.DataValidation.AllowType = CellDataType.Decimal; rangeNumber.DataValidation.ErrorMessage = "Please input correct number!"; rangeNumber.DataValidation.ShowError = true; rangeNumber.Style.KnownColor = ExcelColors.Gray25Percent; sheet.Range["B5"].Text = "Input Date:"; CellRange rangeDate = sheet.Range["B6"]; rangeDate.DataValidation.AllowType = CellDataType.Date; rangeDate.DataValidation.ErrorMessage = "Please input correct date!"; rangeDate.DataValidation.ShowError = true; rangeDate.Style.KnownColor = ExcelColors.Gray25Percent; sheet.AutoFitColumn(2); workbook.SaveToFile("Sample.xls"); ExcelDocViewer(workbook.FileName); }
Private Sub ExcelDocViewer(ByVal fileName As String) Try System.Diagnostics.Process.Start(fileName) Catch End Try End Sub Private Sub btnRun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRun.Click Dim workbook As Workbook = New Workbook() Dim sheet As Worksheet = workbook.Worksheets(0) sheet.Range("B2").Text = "Input Number(3-6):" Dim rangeNumber As CellRange = sheet.Range("B3") rangeNumber.DataValidation.CompareOperator = ValidationComparisonOperator.Between rangeNumber.DataValidation.Formula1 = "3" rangeNumber.DataValidation.Formula2 = "6" rangeNumber.DataValidation.AllowType = CellDataType.Decimal rangeNumber.DataValidation.ErrorMessage = "Please input correct number!" rangeNumber.DataValidation.ShowError = True rangeNumber.Style.KnownColor = ExcelColors.Gray25Percent sheet.Range("B5").Text = "Input Date:" Dim rangeDate As CellRange = sheet.Range("B6") rangeDate.DataValidation.AllowType = CellDataType.Date rangeDate.DataValidation.ErrorMessage = "Please input correct date!" rangeDate.DataValidation.ShowError = True rangeDate.Style.KnownColor = ExcelColors.Gray25Percent sheet.AutoFitColumn(2) workbook.SaveToFile("Sample.xls") ExcelDocViewer(workbook.FileName) End Sub Private Sub btnAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAbout.Click Close() End Sub