private void ApplyMappingInfoAndValidate(ExcelSheet sheet) { // Map columns according to mapping list foreach (ImportFieldMapping mapping in MappingList) { if (!string.IsNullOrEmpty(mapping.ColumnName)) { ExcelSheetColumn column = sheet.Columns[mapping.ColumnName]; column.TargetName = mapping.RequestField; column.Validator = mapping.Validator; } } // Clear all row-level validate results foreach (ExcelSheetRow row in sheet.Rows) { row.RowLevelValidateResult.Clear(); } // Validate whole sheet // Trigger SheetValidate event ExcelSheetValidatingEventArgs arg = new ExcelSheetValidatingEventArgs(sheet); if (ExcelSheetValidating != null) { ExcelSheetValidating(this, arg); } if (!arg.IsCancelled) { // Validate each row for (int index = sheet.DataStartRowIndex; index < sheet.Rows.Count; index++) { ExcelSheetRow row = sheet.Rows[index]; // trigger RowValidate event ExcelSheetRowValidatingEventArgs args = new ExcelSheetRowValidatingEventArgs(row); if (ExcelSheetRowValidating != null) { ExcelSheetRowValidating(this, args); } if (!args.IsCancelled) { // Validate each cell in current row foreach (ExcelSheetCell cell in row.Cells) { cell.Validate(); } } } } }
protected void ucExcelImport_ExcelSheetValidating(object sender, ExcelSheetValidatingEventArgs e) { // Perform whole Excel Sheet level validation ValidateExcelSheet(e.Sheet); }