protected void btnApplyNumberFormats_Click(object sender, EventArgs e)
        {
            // ExStart:ApplyNumberFormats
            // Accessing the reference of the worksheet that is currently active
            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));

            // Putting values to cells
            sheet.Cells["A1"].PutValue("Currency1 Number Format");
            sheet.Cells["A2"].PutValue("Custom Number Format");
            sheet.Cells["B1"].PutValue(7800);
            sheet.Cells["B2"].PutValue(2500);

            // Setting the number format of "B1" cell to Currency1
            Aspose.Cells.GridWeb.TableItemStyle style = sheet.Cells["B1"].GetStyle();
            style.NumberType = NumberType.Currency1;
            sheet.Cells["B1"].SetStyle(style);

            // Setting the custom number format of "B2" cell
            style        = sheet.Cells["B2"].GetStyle();
            style.Custom = "#,##0.0000";
            sheet.Cells["B2"].SetStyle(style);
            // ExEnd:ApplyNumberFormats
        }
Exemplo n.º 2
0
        private void AddTextHyperlinks()
        {
            // ExStart:AddTextHyperlinks
            //Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Adds a text hyperlink that gos to Aspose site and opens in new window
            Hyperlink link1 = sheet.Hyperlinks.AddHyperlink("B1");

            link1.Target = "_blank";

            // Setting text of the hyperlink
            link1.Text = "Aspose";

            // Setting URL of the hyperlink
            link1.Url = "http://www.aspose.com";

            // Setting tool tip of the hyperlink
            link1.ToolTip = "Open Aspose Web Site in new window";

            // Adding hyperlink to the worksheet to open in parent window
            Hyperlink link2 = sheet.Hyperlinks.AddHyperlink("B2");

            link2.Target = "_parent";

            // Setting text of the hyperlink
            link2.Text = "Aspose.Grid Docs";

            // Setting URL of the hyperlink
            link2.Url = "http://www.aspose.com/docs/display/cellsnet/Aspose.Cells.GridWeb";

            // Setting tool tip of the hyperlink
            link2.ToolTip = "Open Aspose.Grid Docs in parent window";
            // ExEnd:AddTextHyperlinks
        }
        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
        }
        protected void btnApplyBorderStyles_Click(object sender, EventArgs e)
        {
            // ExStart:ApplyBorderStyles
            // 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"];

            Aspose.Cells.GridWeb.TableItemStyle style = cell.GetStyle();

            // Setting the border style to Solid
            style.BorderStyle = BorderStyle.Solid;

            // Setting the border width to 2 pixels
            style.BorderWidth = new Unit(2, UnitType.Pixel);

            // Setting the border color to Blue
            style.BorderColor = Color.Blue;

            // Set the cell style
            cell.SetStyle(style);
            // ExEnd:ApplyBorderStyles
        }
        protected void btnCreate_Click(object sender, System.EventArgs e)
        {
            // Fill web worksheet object
            WebWorksheet sheet = GridWeb1.WebWorksheets[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.
            Aspose.Cells.GridWeb.TableItemStyle grandStyle = new Aspose.Cells.GridWeb.TableItemStyle();
            grandStyle.BackColor = Color.Gray;
            grandStyle.ForeColor = Color.Black;
            Aspose.Cells.GridWeb.TableItemStyle subtotalStyle = new Aspose.Cells.GridWeb.TableItemStyle();
            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
        }
        private void AddCellCommandHyperlinks()
        {
            // ExStart:AddCellCommandHyperlinks
            // Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Adding hyperlink to the worksheet
            Hyperlink link1 = sheet.Hyperlinks.AddHyperlink("B8");

            // Setting the action type of the link to CellCommand
            link1.ActionType = HyperlinkActionType.CellCommand;

            // Setting the cell command for the link
            link1.CellCommand = "Click";

            // Setting tool tip of the hyperlink
            link1.ToolTip = "Click Here";

            // Setting URL of the button image that will be displayed as hyperlink
            link1.ImageUrl = "../Images/button.jpg";

            // Resize the row to display image nicely
            sheet.Cells.SetRowHeight(7, 30);
            // ExEnd:AddCellCommandHyperlinks
        }
Exemplo n.º 7
0
        protected void chkSelectedCells_CheckedChanged(object sender, EventArgs e)
        {
            chkAllCells.Checked = false;

            if (chkSelectedCells.Checked)
            {
                // ExStart:MakeSelectedCellsEditable
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Setting all cells of the worksheet to Readonly first
                sheet.SetAllCellsReadonly();

                // Finally, Setting selected cells of the worksheet to Editable
                sheet.SetEditableRange(3, 2, 4, 1);
                // ExEnd:MakeSelectedCellsEditable

                Label1.Text = "4 rows and 1 column are editable starting from row 4 and column 3";
            }
            else
            {
                // ExStart:MakeSelectedCellsReadOnly
                // Accessing the reference of the worksheet that is currently active
                GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];

                // Setting all cells of the worksheet to Editable first
                sheet.SetAllCellsEditable();

                // Finally, Setting selected cells of the worksheet to Readonly
                sheet.SetReadonlyRange(3, 2, 4, 1);
                // ExEnd:MakeSelectedCellsReadOnly

                Label1.Text = "4 rows and 1 column are readonly starting from row 4 and column 3";
            }
        }
Exemplo n.º 8
0
        protected void chkMergeCells_CheckedChanged(object sender, EventArgs e)
        {
            if (chkMergeCells.Checked)
            {
                // ExStart:MergeCells
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Merging cells starting from the cell with 3rd row and 3rd column.
                // 2 rows and 2 columns will be merged from the starting cell
                sheet.Cells.Merge(2, 2, 2, 2);
                // ExEnd:MergeCells

                Label1.Text = "2 rows and 2 columns are merged starting from row 3 and column 3";
            }
            else
            {
                // ExStart:UnmergeCells
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Unmerging cells starting from the cell with 3rd row and 3rd column.
                // 2 rows and 2 columns will be unmerged from the starting cell
                sheet.Cells.UnMerge(2, 2, 2, 2);
                // ExEnd:UnmergeCells

                Label1.Text = "2 rows and 2 columns are unmerged starting from row 3 and column 3";
            }
        }
Exemplo n.º 9
0
        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";
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !GridWeb1.IsPostBack)
            {
                // Create dataset object
                this.dataSet11 = new DataSet1();

                // Create web worksheet object
                WebWorksheet sheet = GridWeb1.WebWorksheets[0];

                // Specifies the datasource for the sheet.
                sheet.DataSource = dataSet11;
                sheet.DataMember = "Products";

                // Creates in-sheet column headers.
                sheet.EnableCreateBindColumnHeader = true;

                // Data cells begin at row 1;
                sheet.BindStartRow = 1;

                // Creates the data field column automatically.
                sheet.CreateAutoGenratedColumns();

                // Modifies a column's number type.
                sheet.BindColumns["UnitPrice"].NumberType = NumberType.Currency3;

                // The "product name" field is required.
                Aspose.Cells.GridWeb.Validation v = new Aspose.Cells.GridWeb.Validation();
                v.IsRequired = true;
                sheet.BindColumns["ProductName"].Validation = v;

                // Modifies column headers' background color.
                for (int i = 0; i < sheet.BindColumns.Count; i++)
                {
                    sheet.BindColumns[i].ColumnHeaderStyle.BackColor = Color.SkyBlue;
                }

                // Create demo database object
                ExampleDatabase db = new ExampleDatabase();

                // Create path to database file
                string path = (this.Master as Site).GetDataDir();

                // Create connection string
                db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Miscellaneous\\Database\\demos.mdb";
                try
                {
                    // Loads data from database.
                    db.oleDbDataAdapter1.Fill(dataSet11);
                }
                finally
                {
                    // Close connection
                    db.oleDbConnection1.Close();
                }

                // Binding.
                sheet.DataBind();
            }
        }
Exemplo n.º 11
0
        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
        }
        // Initialize new bind row.
        private void GridWeb1_InitializeNewBindRow(WebWorksheet sender, object bindObject)
        {
            // Handles the initialize new bind row event.
            MyCustomRecord rec = (MyCustomRecord)bindObject;

            rec.DateField1 = DateTime.Now;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !GridWeb1.IsPostBack)
            {
                // Creates the collection.
                MyCollection  list = new MyCollection();
                System.Random rand = new System.Random();
                for (int i = 0; i < 5; i++)
                {
                    // Create custom record object and set properties
                    MyCustomRecord rec = new MyCustomRecord();
                    rec.DateField1   = DateTime.Now;
                    rec.DoubleField1 = rand.NextDouble();
                    rec.IntField1    = rand.Next();
                    rec.StringField1 = "ABC_" + i;
                    ((IList)list).Add(rec);
                }

                // Create web worksheet object
                WebWorksheet sheet = GridWeb1.WebWorksheets[0];

                // Uses the collection as datasource.
                sheet.DataSource = list;

                // Creates bind columns.
                sheet.CreateAutoGenratedColumns();

                // Sets the DateFiled1's validation to DateTime.
                sheet.BindColumns["DateField1"].Validation.ValidationType = ValidationType.DateTime;

                // Binding.
                sheet.DataBind();
            }
        }
        private void AccessCellByRowColumnIndex()
        {
            // ExStart:AccessCellByRowColumnIndex
            // Accessing the worksheet of the Grid that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Accessing "B1" cell of the worksheet using its row and column indices
            WebCell cell = sheet.Cells[0, 1];

            // Display cell name and value
            Label1.Text += "Cell Value of " + cell.Name + " is " + cell.StringValue + "<br/>";
            // ExEnd:AccessCellByRowColumnIndex
        }
        private void AccessCellByName()
        {
            // ExStart:AccessCellByName
            // Accessing the worksheet of the Grid that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Accessing "B1" cell of the worksheet
            WebCell cell = sheet.Cells["A1"];

            // Display cell name and value
            Label1.Text += "Cell Value of " + cell.Name + " is " + cell.StringValue + "<br/>";
            // ExEnd:AccessCellByName
        }
Exemplo n.º 16
0
        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
        }
Exemplo n.º 17
0
        private void AddStringValue()
        {
            // ExStart:AddCellStringValue
            // Accessing the worksheet of the Grid that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Accessing "B1" cell of the worksheet
            WebCell cell = sheet.Cells["B1"];

            // Accessing & modifying the string value of "B1" cell
            cell.StringValue = "Hello Aspose.Grid";
            // ExEnd:AddCellStringValue
        }
Exemplo n.º 18
0
        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 BindWithInSheetHeaders()
        {
            // Create dataset object
            this.dataSet11 = new DataSet1();

            // Create database object
            ExampleDatabase db = new ExampleDatabase();

            // Create path to database file
            string path = (this.Master as Site).GetDataDir();

            // Create connection string
            db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Miscellaneous\\Database\\demos.mdb";
            try
            {
                // Connects to database and fetches data.
                db.oleDbDataAdapter1.Fill(dataSet11);

                // Create webworksheet object
                WebWorksheet sheet = GridWeb1.WebWorksheets[0];

                // Clears the sheet.
                sheet.Cells.Clear();

                // Enables creating in-sheet headers.
                sheet.EnableCreateBindColumnHeader = true;

                // Data cells begin from row 2.
                sheet.BindStartRow = 2;

                // Creates some title cells.
                sheet.Cells["A1"].PutValue("The Product Table");
                sheet.Cells["A1"].GetStyle().Font.Size       = new FontUnit("20pt");
                sheet.Cells["A1"].GetStyle().HorizontalAlign = HorizontalAlign.Center;
                sheet.Cells["A1"].GetStyle().VerticalAlign   = VerticalAlign.Middle;
                sheet.Cells["A1"].GetStyle().BackColor       = Color.SkyBlue;
                sheet.Cells["A1"].GetStyle().ForeColor       = Color.Blue;
                sheet.Cells.Merge(0, 0, 2, 11);

                // Freezes the header rows.
                sheet.FreezePanes(3, 0, 3, 0);

                // Bind the sheet to the dataset.
                sheet.DataBind();
            }
            finally
            {
                //Close connection
                db.oleDbConnection1.Close();
            }
        }
Exemplo n.º 20
0
    private void BindWithoutInSheetHeaders()
    {
        //Create dataset object
        this.dataSet21 = new DataSet2();

        //Create demo database
        DemoDatabase2 db = new DemoDatabase2();

        //Create path to database file
        string path = Server.MapPath("~");

        path = path.Substring(0, path.LastIndexOf("\\"));

        //Create connection to database
        db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Database\\Northwind.mdb";
        try
        {
            // Connects to database and fetches data.
            // Customers Table.
            db.oleDbDataAdapter1.Fill(dataSet21);
            // Orders Table.
            db.oleDbDataAdapter2.Fill(dataSet21);
            // OrderDetailTable.
            db.oleDbDataAdapter3.Fill(dataSet21);

            // Filter data
            //dataSet21.Customers.DefaultView.RowFilter = "CustomerID<'BSAAA'";

            //Create web worksheet object
            WebWorksheet sheet = GridWeb1.WebWorksheets[0];

            // Clears the sheet.
            sheet.Cells.Clear();

            // Disables creating in-sheet headers.
            sheet.EnableCreateBindColumnHeader = false;

            // Data cells begin from row 0.
            sheet.BindStartRow = 0;

            // Bind the sheet to the dataset.
            sheet.DataSource = dataSet21;
            sheet.DataBind();
        }
        finally
        {
            //Close connection
            db.oleDbConnection1.Close();
        }
    }
        // ExStart:HandleCustomCommandEvent
        // Creating Event Handler for CustomCommand event
        protected void GridWeb1_CustomCommand(object sender, string command)
        {
            // Identifying a specific button by checking its command
            if (command.Equals("MyButton"))
            {
                // Accessing the cells collection of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Putting value to "A1" cell
                sheet.Cells["A1"].PutValue("My Custom Command Button is Clicked.");

                // Set first column width to make the text visible
                sheet.Cells.SetColumnWidth(0, new Unit(200, UnitType.Point));
            }
        }
        // ExStart:HandleCellCommandHyperlinkEvent
        // Event Handler for CellCommand event
        protected void GridWeb1_CellCommand(object sender, Aspose.Cells.GridWeb.CellEventArgs e)
        {
            // Checking the CellCommand of the hyperlink
            if (e.Argument.Equals("Click"))
            {
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Adding value to "C8" cell
                sheet.Cells["C8"].PutValue("Cell Command Hyperlink Clicked");

                // Resize the column to display message nicely
                sheet.Cells.SetColumnWidth(2, 250);
            }
        }
        protected void btnDeleteRow_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // ExStart:DeleteRow
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Get row index entered by user
                int rowIndex = Convert.ToInt16(txtRowIndex.Text.Trim());

                // Delete row at specified index
                sheet.Cells.DeleteRow(rowIndex);
                // ExEnd:DeleteRow
            }
        }
Exemplo n.º 24
0
        protected void btnAddColumn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // ExStart:AddColumn
                // Accessing the reference of the worksheet that is currently active
                WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

                // Get column index entered by user
                int columnIndex = Convert.ToInt16(txtColumnIndex.Text.Trim());

                // Add column at specified index
                sheet.Cells.InsertColumn(columnIndex);
                // ExEnd:AddColumn
            }
        }
Exemplo n.º 25
0
        protected void btnExportDataTable_Click(object sender, EventArgs e)
        {
            // ExStart:ExportDataTable
            // Creating a new DataTable object
            DataTable dataTable = new DataTable();

            // Adding specific columns to the DataTable object
            dataTable.Columns.Add("Name", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Gender", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Age", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Class", System.Type.GetType("System.String"));

            // Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Getting the total number of rows and columns inside the worksheet
            int totalColumns = sheet.Cells.MaxColumn + 1;
            int totalRows    = sheet.Cells.MaxRow + 1;

            // Exporting the data of the active worksheet to a specific DataTable object
            dataTable = sheet.Cells.Export(0, 0, totalRows, totalColumns, true, true);

            // Display exported data table in GridView
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            // ExEnd:ExportDataTable

            // ExStart:ExportNewDataTable
            // Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet1 = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Getting the total number of rows and columns inside the worksheet
            int totalColumns1 = sheet.Cells.MaxColumn + 1;
            int totalRows1    = sheet.Cells.MaxRow + 1;

            // Exporting the data of the active worksheet to a new DataTable object
            DataTable dt = sheet.Cells.Export(0, 0, totalRows1, totalColumns1, true, true);

            // Display exported data table in GridView
            GridView2.DataSource = dataTable;
            GridView2.DataBind();
            // ExEnd:ExportNewDataTable

            trResult.Visible = true;
        }
        private void BindWithoutInSheetHeaders()
        {
            // Create dataset object
            this.dataSet21 = new DataSet2();

            // Create demo database
            DemoDatabase2 db = new DemoDatabase2();

            // Create path to database file
            string path = (this.Master as Site).GetDataDir();

            // Create connection string
            db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Miscellaneous\\Database\\Northwind.mdb";
            try
            {
                // Connects to database and fetches data.
                // Customers Table.
                db.oleDbDataAdapter1.Fill(dataSet21);
                // Orders Table.
                db.oleDbDataAdapter2.Fill(dataSet21);
                // OrderDetailTable.
                db.oleDbDataAdapter3.Fill(dataSet21);

                // Create web worksheet object
                WebWorksheet sheet = GridWeb1.WebWorksheets[0];

                // Clears the sheet.
                sheet.Cells.Clear();

                // Disables creating in-sheet headers.
                sheet.EnableCreateBindColumnHeader = false;

                // Data cells begin from row 0.
                sheet.BindStartRow = 0;

                // Bind the sheet to the dataset.
                sheet.DataSource = dataSet21;
                sheet.DataBind();
            }
            finally
            {
                //Close connection
                db.oleDbConnection1.Close();
            }
        }
        private void BindWithoutInSheetHeaders()
        {
            // Create dataset object
            this.dataSet11 = new DataSet1();

            // Create database object
            ExampleDatabase db = new ExampleDatabase();

            // Create path to database file
            string path = (this.Master as Site).GetDataDir();

            // Create connection string
            db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Miscellaneous\\Database\\demos.mdb";
            try
            {
                // Connects to database and fetches data.
                db.oleDbDataAdapter1.Fill(dataSet11);

                // Create web worksheet object
                WebWorksheet sheet = GridWeb1.WebWorksheets[0];

                // Clears the sheet.
                sheet.Cells.Clear();
                sheet.Cells.UnMerge(0, 0, 2, 11);

                // Disables creating in-sheet headers.
                sheet.EnableCreateBindColumnHeader = false;

                // Data cells begin from row 0.
                sheet.BindStartRow = 0;

                // Unfreezes the header rows.
                sheet.UnfreezePanes();

                // Bind the sheet to the dataset.
                sheet.DataBind();
            }
            finally
            {
                // Close database connection
                db.oleDbConnection1.Close();
            }
        }
Exemplo n.º 28
0
    private void BindWithoutInSheetHeaders()
    {
        //Create database object
        this.dataSet11 = new Aspose.Cells.GridWeb.DemosCS.DataBind.DataSet1();

        //Create demo database object
        DemoDatabase db = new DemoDatabase();

        //Create path to database file
        string path = Server.MapPath("~");

        path = path.Substring(0, path.LastIndexOf("\\"));

        //Create connection string to database file
        db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Database\\demos.mdb";
        try
        {
            // Connects to database and fetches data.
            db.oleDbDataAdapter1.Fill(dataSet11);

            //Create web worksheet object
            WebWorksheet sheet = GridWeb1.WebWorksheets[0];

            // Clears the sheet.
            sheet.Cells.Clear();
            sheet.Cells.UnMerge(0, 0, 2, 11);
            // Disables creating in-sheet headers.
            sheet.EnableCreateBindColumnHeader = false;

            // Data cells begin from row 0.
            sheet.BindStartRow = 0;
            // Unfreezes the header rows.
            sheet.UnfreezePanes();
            // Bind the sheet to the dataset.
            sheet.DataBind();
        }
        finally
        {
            //Close database connection
            db.oleDbConnection1.Close();
        }
    }
        protected void btnUpdateHyperlinks_Click(object sender, EventArgs e)
        {
            // ExStart:AccessHyperlinks
            // Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Accessing a specific cell that contains hyperlink
            WebCell cell = sheet.Cells["B1"];

            // Accessing the hyperlink from the specific cell
            Hyperlink link = sheet.Hyperlinks.GetHyperlink(cell);

            if (link != null)
            {
                // Modifying the text and URL of hyperlink
                link.Text = "Aspose.Blogs";
                link.Url  = "http://www.aspose.com/Community/Blogs";
            }
            // ExEnd:AccessHyperlinks
        }
        private void AddImageHyPerlinks()
        {
            // ExStart:AddImageHyperlinks
            // Accessing the reference of the worksheet that is currently active
            WebWorksheet sheet = GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];

            // Adding hyperlink to the worksheet
            Hyperlink link1 = sheet.Hyperlinks.AddHyperlink("B5");

            link1.Target = "_blank";

            // Setting URL of the image that will be displayed as hyperlink
            link1.ImageUrl = "../Images/Aspose.Banner.gif";

            // Setting URL of the hyperlink
            link1.Url = "http://www.aspose.com";

            // Setting tool tip of the hyperlink
            link1.ToolTip = "Open Aspose Web Site in new window";

            // Resize the row to display image nicely
            sheet.Cells.SetRowHeight(4, 40);

            // Adding hyperlink to the worksheet
            Hyperlink link2 = sheet.Hyperlinks.AddHyperlink("B6");

            link2.Target = "_blank";

            // Setting URL of the image that will be displayed as hyperlink
            link2.ImageUrl = "../Images/Aspose.Grid.gif";

            // Setting URL of the hyperlink
            link2.Url = "http://www.aspose.com/docs/display/cellsnet/Aspose.Cells.GridWeb";

            // Setting tool tip of the hyperlink
            link2.ToolTip = "Open Aspose.Grid Docs in new window";

            // Setting text of the hyperlink. It will be displayed if image is not displayed due to some reason
            link2.Text = "Open Aspose.Grid Docs Page in new window";
            // ExEnd:AddImageHyperlinks
        }
  private DataTable CreateDataTable(WebWorksheet sheet, WebCellArea area)
  {
    // Create a new DataTable.
    System.Data.DataTable myDataTable = new DataTable("FromDataTable");
    // Declare variables for DataColumn and DataRow objects.
    DataColumn myDataColumn;
    DataRow myDataRow;

    for (int i = area.StartColumn; i < area.EndColumn; i++)
    {
      // Create new DataColumn, set DataType, ColumnName and add to DataTable.    
      myDataColumn = new DataColumn();
      myDataColumn.DataType = System.Type.GetType("System.String");
      myDataColumn.ColumnName = sheet.Cells[area.StartRow, i].Value.ToString();
      // Add the Column to the DataColumnCollection.
      myDataTable.Columns.Add(myDataColumn);
    }

    // Create six column.
    myDataColumn = new DataColumn();
    myDataColumn.DataType = System.Type.GetType("System.Int32");
    myDataColumn.ColumnName = sheet.Cells[area.StartRow, area.EndColumn].Value.ToString();
    // Add the column to the table.
    myDataTable.Columns.Add(myDataColumn);

    for (int i = area.StartRow + 1; i <= area.EndRow; i++)
    {
      myDataRow = myDataTable.NewRow();
      for (int j = area.StartColumn; j <= area.EndColumn; j++)
      {
        myDataRow[sheet.Cells[0, j].Value.ToString()] = sheet.Cells[i, j].Value;
      }
      myDataTable.Rows.Add(myDataRow);
    }

    return myDataTable;
  }
Exemplo n.º 32
0
 // Initialize new bind row.
 private void GridWeb1_InitializeNewBindRow(WebWorksheet sender, object bindObject)
 {
   // Handles the initialize new bind row event.
   MyCustomRecord rec = (MyCustomRecord)bindObject;
   rec.DateField1 = DateTime.Now;
 }