Exemple #1
0
        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
            GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];

            sheet.Cells.Clear();
            sheet.Cells.SetColumnWidth(0, 50);
            sheet.Cells.SetRowHeight(0, 40);

            // Accessing a specific cell of the worksheet
            GridCell cell = sheet.Cells["A1"];

            // Inserting a value in cell A1
            cell.PutValue("Aspose.Cells.GridWeb");

            var style = cell.Style;

            // Setting font, color and alignment of cell
            style.Font.Size       = new FontUnit("12pt");
            style.Font.Bold       = true;
            style.ForeColor       = Color.Blue;
            style.BackColor       = Color.Aqua;
            style.HorizontalAlign = HorizontalAlign.Center;

            // Set the cell style
            cell.CopyStyle(style);
            sheet.AutoFitColumn(0);
            // ExEnd:ApplyFontStyles
        }
Exemple #2
0
        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
            GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];

            sheet.Cells.Clear();
            sheet.Cells.SetColumnWidth(0, 50);
            sheet.Cells.SetRowHeight(0, 40);

            // Accessing a specific cell of the worksheet
            GridCell cell = sheet.Cells["A1"];

            var style = cell.Style;

            // Setting the border style, width and color
            style.BorderStyle = BorderStyle.Solid;
            style.BorderWidth = new Unit(2, UnitType.Pixel);
            style.BorderColor = Color.Blue;

            // Set the cell style
            cell.CopyStyle(style);
            // ExEnd:ApplyBorderStyles
        }
        // 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);
                }
            }
        }