protected void btnAddCustomValidation_Click(object sender, EventArgs e) { // ExStart:AddCustomValidation // Accessing the cells collection of the worksheet that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B1" cell WebCell cell = sheet.Cells[0, 1]; // Putting value to "B1" cell cell.PutValue("Date (yyyy-mm-dd):"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating a custom expression validation for the "C1" cell cell.CreateValidation(ValidationType.CustomExpression, true); // Setting regular expression for the validation to accept dates in yyyy-mm-dd format cell.Validation.RegEx = @"\d{4}-\d{2}-\d{2}"; // ExEnd:AddCustomValidation sheet.Cells.SetColumnWidth(1, new Unit(100, UnitType.Point)); // Assigning the name of JavaScript function to OnValidationErrorClientFunction property of GridWeb GridWeb1.OnValidationErrorClientFunction = "ValidationErrorFunction"; }
protected void btnAddListValidation_Click(object sender, EventArgs e) { // ExStart:AddListValidation // Accessing the cells collection of the worksheet that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B1" cell WebCell cell = sheet.Cells[0, 1]; // Putting value to "B1" cell cell.PutValue("Select Course:"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating List validation for the "C1" cell cell.CreateValidation(ValidationType.List, true); // Adding values to List validation cell.Validation.ValueList.Add("Fortran"); cell.Validation.ValueList.Add("Pascal"); cell.Validation.ValueList.Add("C++"); cell.Validation.ValueList.Add("Visual Basic"); cell.Validation.ValueList.Add("Java"); cell.Validation.ValueList.Add("C#"); // ExEnd:AddListValidation }
private void InitGridWeb() { // ExStart:WriteClientSideScript // Assigning the name of JavaScript function to OnSubmitClientFunction property of GridWeb GridWeb1.OnSubmitClientFunction = "ConfirmFunction"; // Assigning the name of JavaScript function to OnValidationErrorClientFunction property of GridWeb GridWeb1.OnValidationErrorClientFunction = "ValidationErrorFunction"; // Accessing the cells collection of the worksheet that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B1" cell WebCell cell = sheet.Cells[0, 1]; // Putting value to "B1" cell cell.PutValue("Date (yyyy-mm-dd):"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating a custom expression validation for the "C1" cell cell.CreateValidation(ValidationType.CustomExpression, true); // Setting regular expression for the validation to accept dates in yyyy-mm-dd format cell.Validation.RegEx = @"\d{4}-\d{2}-\d{2}"; // ExEnd:WriteClientSideScript }
private void AddDoubleValue() { // ExStart:AddCellDoubleValue // Accessing the worksheet of the Grid that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B5" cell of the worksheet WebCell cell = sheet.Cells["B5"]; // Putting a numeric value as string in "B5" cell that will be converted to a suitable data type automatically cell.PutValue("19.4", true); // ExEnd:AddCellDoubleValue }
private void AddIntValue() { // ExStart:AddCellIntValue // Accessing the worksheet of the Grid that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B3" cell of the worksheet WebCell cell = sheet.Cells["B3"]; // Putting a value in "B3" cell cell.PutValue(30); // ExEnd:AddCellIntValue }
protected void btnApplyFontStyles_Click(object sender, EventArgs e) { // ExStart:ApplyFontStyles // Accessing the reference of the worksheet that is currently active and resize first row and column WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; sheet.Cells.Clear(); sheet.Cells.SetColumnWidth(0, new Unit(200, UnitType.Point)); sheet.Cells.SetRowHeight(0, new Unit(50, UnitType.Point)); // Accessing a specific cell of the worksheet WebCell cell = sheet.Cells["A1"]; // Inserting a value in cell A1 cell.PutValue("Aspose.Cells.GridWeb"); Aspose.Cells.GridWeb.TableItemStyle style = cell.GetStyle(); // Setting the font size to 12 points style.Font.Size = new FontUnit("12pt"); // Setting font style to Bold style.Font.Bold = true; // Setting foreground color of font to Blue style.ForeColor = Color.Blue; // Setting background color of font to Aqua style.BackColor = Color.Aqua; // Setting the horizontal alignment of font to Center style.HorizontalAlign = HorizontalAlign.Center; // Set the cell style cell.SetStyle(style); // ExEnd:ApplyFontStyles }
protected void btnAddDropDownListValidation_Click(object sender, EventArgs e) { // ExStart:AddDropDownListValidation // Accessing the cells collection of the worksheet that is currently active WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex]; // Accessing "B1" cell WebCell cell = sheet.Cells[0, 1]; // Putting value to "B1" cell cell.PutValue("Select Degree:"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating DropDownList validation for the "C1" cell cell.CreateValidation(ValidationType.DropDownList, true); // Adding values to DropDownList validation cell.Validation.ValueList.Add("Bachelor"); cell.Validation.ValueList.Add("Master"); cell.Validation.ValueList.Add("Doctor"); // ExEnd:AddDropDownListValidation }