protected void btnCreate_Click(object sender, System.EventArgs e) { // Fill web worksheet object GridWorksheet sheet = GridWeb1.WorkSheets[0]; // Removes the created subtotal first. //sheet.RemoveSubtotal(); // Creates the subtotal. int groupByIndex; if (ddlSort.SelectedItem.Value == "CategoryName") groupByIndex = 1; else groupByIndex = 2; // Creates GrandTotal and Subtotal style. GridTableItemStyle grandStyle = new GridTableItemStyle(); grandStyle.BackColor = Color.Gray; grandStyle.ForeColor = Color.Black; GridTableItemStyle subtotalStyle = new GridTableItemStyle(); subtotalStyle.BackColor = Color.SkyBlue; subtotalStyle.ForeColor = Color.Black; // ExStart:CreateSubTotal sheet.CreateSubtotal(0, sheet.Cells.MaxRow, groupByIndex, (SubtotalFunction)System.Enum.Parse(typeof(SubtotalFunction), ddlFunction.SelectedItem.Value), new int[] { 1, 2, 3, 4, 5 } , ddlFunction.SelectedItem.Text, grandStyle, subtotalStyle, NumberType.General, null); // ExEnd:CreateSubTotal }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // ExStart:ShowPercentageFormat // Access cell A1 of first gridweb worksheet Data.GridCell cellA1 = GridWeb1.WorkSheets[0].Cells["A1"]; // Access cell style and set its number format to 10 which is a Percentage 0.00% format GridTableItemStyle st = cellA1.Style; st.NumberType = 10; cellA1.Style = st; // ExEnd:ShowPercentageFormat } }
private void InitGridWeb() { // ExStart:SetCellPercentageFormat // Access cell A1 of first gridweb worksheet GridCell cellA1 = GridWeb1.WorkSheets[0].Cells["A1"]; // Access cell style and set its number format to 10 which is a Percentage 0.00% format GridTableItemStyle st = cellA1.Style; st.NumberType = 10; cellA1.Style = st; // ExEnd:SetCellPercentageFormat cellA1.PutValue(0.03); }
private void InitData() { // Gets the web application's path. string path = (this.Master as Site).GetDataDir(); string fileName = path + "\\Worksheets\\Sort.xls"; // Imports from an excel file. GridWeb1.ImportExcelFile(fileName); // Creates sorting header style. GridTableItemStyle itemStyle = new GridTableItemStyle(); itemStyle.BorderStyle = BorderStyle.Outset; itemStyle.BorderWidth = 2; itemStyle.BorderColor = Color.White; itemStyle.BackColor = Color.Silver; itemStyle.HorizontalAlign = HorizontalAlign.Center; itemStyle.VerticalAlign = VerticalAlign.Middle; // Creates Hyperlinks Sheet1. Sorts from top to bottom orientation. GridHyperlink cellcmd; GridCells cells0 = GridWeb1.WorkSheets[0].Cells; cells0["A1"].CopyStyle(itemStyle); GridHyperlinkCollection ghc = GridWeb1.WorkSheets[0].Hyperlinks; int i = ghc.Add("A1", ""); cellcmd = ghc[i]; cellcmd.Command = "A1"; cellcmd.ScreenTip = "Sorts Descending"; cellcmd.TextToDisplay = "OrderId"; cells0["B1"].CopyStyle(itemStyle); cellcmd = ghc[ghc.Add("B1", "")]; cellcmd.Command = "B1"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Sales Amout"; cells0["C1"].CopyStyle(itemStyle); cellcmd = ghc[ghc.Add("C1", "")]; cellcmd.Command = "C1"; cellcmd.ScreenTip = "Sorts Descending"; cellcmd.TextToDisplay = "Percent of Saler's Total"; cells0["D1"].CopyStyle(itemStyle); cellcmd = ghc[ghc.Add("D1", "")]; cellcmd.Command = "D1"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Percent of Country Total"; // Creates Hyperlinks Sheet2. Sorts from left to right orientation. GridCells cells1 = GridWeb1.WorkSheets[1].Cells; GridHyperlinkCollection ghcb = GridWeb1.WorkSheets[1].Hyperlinks; cells1["A1"].CopyStyle(itemStyle); cellcmd = ghcb[ghcb.Add("A1", "")]; cellcmd.Command = "1A1"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Product"; cells1["A2"].CopyStyle(itemStyle); cellcmd = ghcb[ghcb.Add("A2", "")]; cellcmd.Command = "1A2"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Category"; cells1["A3"].CopyStyle(itemStyle); cellcmd = ghcb[ghcb.Add("A3", "")]; cellcmd.Command = "1A3"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Package"; cells1["A4"].CopyStyle(itemStyle); cellcmd = ghcb[ghcb.Add("A4", "")]; cellcmd.Command = "1A4"; cellcmd.ScreenTip = "Sorts Ascending"; cellcmd.TextToDisplay = "Quantity"; }
private void LoadGrid() { // Define maximum rows and columns GridWeb1.MaxColumn = 3; GridWeb1.MaxRow = 5; // Create web worksheet object GridWorksheet sheet = GridWeb1.WorkSheets[0]; // Clear worksheet content sheet.Cells.Clear(); // Adding a sample value and formatting to "B1" cell sheet.Cells["B1"].PutValue("BMI Calculator"); sheet.Cells["B1"].Style.BackColor = Color.Yellow; sheet.Cells["B1"].Style.ForeColor = Color.Green; sheet.Cells["B1"].Style.Font.Bold = true; sheet.Cells["B1"].Style.HorizontalAlign = HorizontalAlign.Center; sheet.Cells["B1"].Style.VerticalAlign = VerticalAlign.Middle; // Merge B1 and B2 columns sheet.Cells.Merge(0, 1, 1, 2); // Set columns width sheet.Cells.SetColumnWidth(1, 200); sheet.Cells.SetColumnWidth(2, 200); // Adding a sample value and formatting to "B3" cell sheet.Cells["B3"].PutValue("Your Height(CM):"); sheet.Cells["B3"].Style.BackColor = Color.Blue; sheet.Cells["B3"].Style.ForeColor = Color.Silver; // Adding a sample value and formatting to "B4" cell sheet.Cells["B4"].PutValue("Your Weight(KG):"); sheet.Cells["B4"].Style.BackColor = Color.Blue; sheet.Cells["B4"].Style.ForeColor = Color.Silver; // Adding a sample value and formatting to "B5" cell sheet.Cells["B5"].PutValue("Your BMI is:"); sheet.Cells["B5"].Style.BackColor = Color.Green; sheet.Cells["B5"].Style.ForeColor = Color.Silver; // Adding a sample value and formatting to "B6" cell sheet.Cells["B6"].PutValue("Evaluation:"); sheet.Cells["B6"].Style.BackColor = Color.Green; sheet.Cells["B6"].Style.ForeColor = Color.Silver; //Adding a formula value and formatting to "C5" cell sheet.Cells["C5"].Formula = "=C4/(C3/100)^2"; sheet.Cells["C5"].Style.BackColor = Color.LightGreen; sheet.Cells["C5"].Style.ForeColor = Color.Red; sheet.Cells["C5"].Style.HorizontalAlign = HorizontalAlign.Right; GridTableItemStyle style = new GridTableItemStyle(); style.Custom = "0.00"; sheet.Cells["C5"].Style = style; // Adding a formula value and formatting to "C6" cell sheet.Cells["C6"].Formula = "=IF(C5<18.5, \"Too Thin\", IF(C5<21, \"Good\", IF(C5<=23, \"Very Good\", IF(C5<=25, \"Good\", \"Too Fat\"))))"; sheet.Cells["C6"].Style.BackColor = Color.LightGreen; sheet.Cells["C6"].Style.ForeColor = Color.Red; sheet.Cells["C6"].Style.HorizontalAlign = HorizontalAlign.Right; // Adding validation and formatting to "C3" cell sheet.Cells["C3"].CreateValidation(GridValidationType.WholeNumber, true); sheet.Cells["C3"].Style.HorizontalAlign = HorizontalAlign.Right; // Adding validation and formatting to "C4" cell sheet.Cells["C4"].CreateValidation(GridValidationType.WholeNumber, true); sheet.Cells["C4"].Style.HorizontalAlign = HorizontalAlign.Right; // Set GridWeb properties GridWeb1.EnableAJAX = true; GridWeb1.EnableClientColumnOperations = false; GridWeb1.EnableClientFreeze = false; GridWeb1.EnableClientMergeOperations = false; GridWeb1.EnableClientRowOperations = false; GridWeb1.EnableStyleDialogbox = false; }
private void InitData() { GridWeb1.WorkSheets.Clear(); GridWorksheet sheet = GridWeb1.WorkSheets.Add("Students"); GridCells cells = sheet.Cells; cells[0, 0].PutValue("Name"); GridTableItemStyle cellstyle = cells[0, 0].Style; cellstyle.Font.Size = new FontUnit("10pt"); cellstyle.Font.Bold = true; cellstyle.ForeColor = Color.Black; cellstyle.HorizontalAlign = HorizontalAlign.Center; cellstyle.BorderWidth = 1; cells[0, 0].Style = cellstyle; cells[0, 1].PutValue("Gender"); cells[0, 1].Style = cellstyle; cells[0, 2].PutValue("Age"); cells[0, 2].Style = cellstyle; cells[0, 3].PutValue("Class"); cells[0, 3].Style = cellstyle; cells[1, 0].PutValue("Jack"); cells[1, 1].PutValue("M"); cells[1, 2].PutValue(19); cells[1, 3].PutValue("One"); cells[2, 0].PutValue("Tome"); cells[2, 1].PutValue("M"); cells[2, 2].PutValue(20); cells[2, 3].PutValue("Four"); cells[3, 0].PutValue("Jeney"); cells[3, 1].PutValue("W"); cells[3, 2].PutValue(18); cells[3, 3].PutValue("Two"); cells[4, 0].PutValue("Marry"); cells[4, 1].PutValue("W"); cells[4, 2].PutValue(17); cells[4, 3].PutValue("There"); cells[5, 0].PutValue("Amy"); cells[5, 1].PutValue("W"); cells[5, 2].PutValue(16); cells[5, 3].PutValue("Four"); cells[6, 0].PutValue("Ben"); cells[6, 1].PutValue("M"); cells[6, 2].PutValue(17); cells[6, 3].PutValue("Four"); cells.SetColumnWidth(0, 10); cells.SetColumnWidth(1, 10); cells.SetColumnWidth(2, 10); cells.SetColumnWidth(3, 10); }
// Handles the "import" button click event and load data from a dataview object. protected void Button1_Click(object sender, EventArgs e) { // ExStart:ImportDataView // Connect database System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(); System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1 = new OleDbDataAdapter(); System.Data.OleDb.OleDbCommand oleDbSelectCommand1 = new OleDbCommand(); string path = (this.Master as Site).GetDataDir(); oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Worksheets\\Database\\Northwind.mdb"; oleDbSelectCommand1.Connection = oleDbConnection1; oleDbDataAdapter1.SelectCommand = oleDbSelectCommand1; DataTable dataTable1 = new DataTable(); dataTable1.Reset(); // Queries database. try { oleDbSelectCommand1.CommandText = "SELECT CategoryID, CategoryName, Description FROM Categories"; oleDbDataAdapter1.Fill(dataTable1); } catch { } finally { oleDbConnection1.Close(); } // Imports data from dataview object. dataTable1.TableName = "Categories"; GridWeb1.WorkSheets.Clear(); GridWeb1.WorkSheets.ImportDataView(dataTable1.DefaultView, null, null); // Imports data from dataview object with sheet name and position specified. GridWeb1.WorkSheets.ImportDataView(dataTable1.DefaultView, null, null, "SpecifiedName&Position", 2, 1); // ExEnd:ImportDataView // Resize cells GridCells cells = GridWeb1.WorkSheets[0].Cells; // Sets column width. cells.SetColumnWidth(0, 10); cells.SetColumnWidth(1, 10); cells.SetColumnWidth(2, 30); cells.SetRowHeight(2, 30); GridCells cellsb = GridWeb1.WorkSheets[1].Cells; cellsb.SetColumnWidth(1, 10); cellsb.SetColumnWidth(2, 10); cellsb.SetColumnWidth(3, 30); cellsb.SetRowHeight(4, 30); // Add style to cells GridTableItemStyle style = new GridTableItemStyle(); style.HorizontalAlign = HorizontalAlign.Center; style.BorderStyle = BorderStyle.Solid; style.BorderColor = Color.Black; style.BorderWidth = 1; for (int i = 1; i <= cells.MaxRow; i++) { for (int j = 0; j <= cells.MaxColumn; j++) { GridCell cell = cells[i, j]; cell.CopyStyle(style); } } for (int i = 3; i <= cellsb.MaxRow; i++) { for (int j = 1; j <= cellsb.MaxColumn; j++) { GridCell cell = cellsb[i, j]; cell.CopyStyle(style); } } }
private void InitData() { GridWeb2.WorkSheets.Clear(); GridWeb2.WorkSheets.Add("Students"); GridWorksheet sheet = GridWeb2.WorkSheets[0]; GridCells cells = sheet.Cells; cells[0, 0].PutValue("Name"); GridTableItemStyle itemstyle = cells[0, 0].Style; itemstyle.Font.Size = new FontUnit("10pt"); itemstyle.Font.Bold = true; itemstyle.ForeColor = Color.Black; itemstyle.HorizontalAlign = HorizontalAlign.Center; itemstyle.BorderWidth = 1; cells[0, 0].Style = itemstyle; cells[1, 0].PutValue("Jack"); cells[1, 1].PutValue("M"); cells[1, 2].PutValue(19); cells[1, 3].PutValue("One"); cells[2, 0].PutValue("Tome"); cells[2, 1].PutValue("M"); cells[2, 2].PutValue(20); cells[2, 3].PutValue("Four"); cells[3, 0].PutValue("Jeney"); cells[3, 1].PutValue("W"); cells[3, 2].PutValue(18); cells[3, 3].PutValue("Two"); cells[4, 0].PutValue("Marry"); cells[4, 1].PutValue("W"); cells[4, 2].PutValue(17); cells[4, 3].PutValue("There"); cells[5, 0].PutValue("Amy"); cells[5, 1].PutValue("W"); cells[5, 2].PutValue(16); cells[5, 3].PutValue("Four"); cells[6, 0].PutValue("Ben"); cells[6, 1].PutValue("M"); cells[6, 2].PutValue(17); cells[6, 3].PutValue("Four"); GridCell cell = cells[0, 1]; GridTableItemStyle style = cell.Style; style.Font.Size = new FontUnit("22pt"); style.Wrap = false; style.BackColor = Color.Gray; style.BorderStyle = BorderStyle.Solid; style.BorderWidth = new Unit(1, UnitType.Pixel); style.BorderColor = Color.Blue; style.RightBorderStyle.BorderColor = Color.Red; style.RightBorderStyle.BorderStyle = BorderStyle.Solid; style.RightBorderStyle.BorderWidth = new Unit(2, UnitType.Pixel); style.BottomBorderStyle.BorderColor = Color.YellowGreen; style.BottomBorderStyle.BorderStyle = BorderStyle.Solid; style.BottomBorderStyle.BorderWidth = new Unit(40, UnitType.Pixel); cell.Style = style; cells.SetRowHeight(0, 60); cells.SetColumnWidth(0, 80); cells.SetColumnWidth(1, 80); cells.SetColumnWidth(2, 80); cells.SetColumnWidth(3, 80); }
private void InitData() { GridWeb1.WorkSheets.Clear(); GridWorksheet sheet = GridWeb1.WorkSheets.Add("Students"); GridCells cells = sheet.Cells; cells[0, 0].PutValue("Name"); GridTableItemStyle cellstyle = cells[0, 0].Style; cellstyle.Font.Size = new FontUnit("10pt"); cellstyle.Font.Bold = true; cellstyle.ForeColor = Color.Black; cellstyle.HorizontalAlign = HorizontalAlign.Center; cellstyle.BorderWidth = 1; cells[0, 0].Style = cellstyle; cells[1, 0].PutValue("Jack"); cells[1, 1].PutValue("M"); cells[1, 2].PutValue(19); cells[1, 3].PutValue("One"); cells[2, 0].PutValue("Tome"); cells[2, 1].PutValue("M"); cells[2, 2].PutValue(20); cells[2, 3].PutValue("Four"); cells[3, 0].PutValue("Jeney"); cells[3, 1].PutValue("W"); cells[3, 2].PutValue(18); cells[3, 3].PutValue("Two"); cells[4, 0].PutValue("Marry"); cells[4, 1].PutValue("W"); cells[4, 2].PutValue(17); cells[4, 3].PutValue("There"); cells[5, 0].PutValue("Amy"); cells[5, 1].PutValue("W"); cells[5, 2].PutValue(16); cells[5, 3].PutValue("Four"); cells[6, 0].PutValue("Ben"); cells[6, 1].PutValue("M"); cells[6, 2].PutValue(17); cells[6, 3].PutValue("Four"); GridCell cell = cells[0, 1]; Aspose.Cells.GridWeb.GridTableItemStyle style = cell.Style; style.Font.Size = new FontUnit("22pt"); style.Wrap = false; //style.BackColor = Color.Gray; style.RightBorderStyle.BorderColor = Color.Red; style.RightBorderStyle.BorderStyle = BorderStyle.Dotted; style.BottomBorderStyle.BorderColor = Color.Green; style.BottomBorderStyle.BorderStyle = BorderStyle.Groove; style.TopBorderStyle.BorderColor = Color.Yellow; style.TopBorderStyle.BorderStyle = BorderStyle.Inset; style.LeftBorderStyle.BorderColor = Color.Coral; style.LeftBorderStyle.BorderStyle = BorderStyle.Solid; cells[0, 1].Style = style; Aspose.Cells.GridWeb.GridTableItemStyle vtstyle1 = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle1.CopyFrom(style); vtstyle1.LeftBorderStyle.BorderWidth = new Unit(1, UnitType.Pixel); vtstyle1.TopBorderStyle.BorderWidth = new Unit(1, UnitType.Pixel); // cells[0, 0].SetStyle(vtstyle1); // cells[1, 2].SetStyle(style); Aspose.Cells.GridWeb.GridTableItemStyle vtstyle2 = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle2.CopyFrom(style); vtstyle2.LeftBorderStyle.BorderWidth = new Unit(10, UnitType.Pixel); // style.LeftBorderStyle.BorderWidth = new Unit(50, UnitType.Pixel); // cells[3, 0].SetStyle(vtstyle2); Aspose.Cells.GridWeb.GridTableItemStyle vtstyle3 = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle3.CopyFrom(style); vtstyle3.TopBorderStyle.BorderWidth = new Unit(1, UnitType.Pixel); vtstyle3.BottomBorderStyle.BorderWidth = new Unit(80, UnitType.Pixel); // cells[0, 1].SetStyle(vtstyle3); Aspose.Cells.GridWeb.GridTableItemStyle vtstyle4 = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle4.CopyFrom(vtstyle3); vtstyle4.TopBorderStyle.BorderWidth = new Unit(1, UnitType.Pixel); vtstyle4.BottomBorderStyle.BorderWidth = new Unit(50, UnitType.Pixel); // cells[0, 2].SetStyle(vtstyle4); Aspose.Cells.GridWeb.GridTableItemStyle vtstyle5 = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle5.CopyFrom(vtstyle3); vtstyle5.TopBorderStyle.BorderWidth = new Unit(1, UnitType.Pixel); vtstyle5.BottomBorderStyle.BorderWidth = new Unit(150, UnitType.Pixel); vtstyle5.RightBorderStyle.BorderWidth = new Unit(40, UnitType.Pixel); vtstyle5.LeftBorderStyle.BorderWidth = new Unit(20, UnitType.Pixel); // cells[1, 1].SetStyle(vtstyle5); Aspose.Cells.GridWeb.GridTableItemStyle vtstyle = new Aspose.Cells.GridWeb.GridTableItemStyle(); vtstyle.CopyFrom(style); vtstyle.RightBorderStyle.BorderWidth = new Unit(50, UnitType.Pixel); // cells[1, 4].SetStyle(vtstyle); // cells[1, 4] // WebCell cellheader = sheet. // cellheader.SetStyle(style); // GridWeb1.SetHeaderBarStyle(new HeaderBarStyle() ); cells.SetRowHeight(0, 20); cells.SetRowHeight(1, 20); cells.SetColumnWidth(0, 10); cells.SetColumnWidth(1, 10); cells.SetColumnWidth(2, 10); cells.SetColumnWidth(3, 10); }