GridWeb - How to set default Vertical Align

I have a grid and want the column headings vertically alignment to be Centered.

I can not find a property to set vertical alignment in the GridWeb asp control so I set it in code.

But there is a delay in vertically aligning the text. The grid gets displayed with the column top-aligned then after a few seconds it shifts so that they are center-aligned as I want.

I'm using aspose.cells.gridweb version 2.7.18.2001

asp:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="dynamicAsposeGridWeb.WebForm1" %>

<%@ Register Assembly="Aspose.Cells.GridWeb" Namespace="Aspose.Cells.GridWeb" TagPrefix="acw" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<acw:gridweb ID="gridWeb1" runat="server"></acw:gridweb>

</div>

</form>

</body>

</html>

code behind:

using System;

using System.Data;

using System.Data.OleDb;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Aspose.Cells.GridWeb;

using Aspose.Cells.GridWeb.Data;

using System.Drawing;

namespace dynamicAsposeGridWeb

{

public partial class WebForm1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack == true)

{

License license = new License();

license.SetLicense("Aspose.Cells.lic");

String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Aspose\\Aspose.Cells for .NET\\Demos\\Common\\Database\\demos.mdb";

OleDbConnection conn = new OleDbConnection(connString);

OleDbCommand cmd = new OleDbCommand("SELECT *, -1 FROM PRODUCTS", conn); //<-- neg value was crashing

OleDbDataAdapter da = new OleDbDataAdapter(cmd);

DataSet ds = new DataSet();

conn.Open();

da.Fill(ds, "PRODUCTS");

conn.Close();

WebWorksheet ws = gridWeb1.WebWorksheets[0];

ws.Cells.Clear();

ws.EnableCreateBindColumnHeader = true;

ws.DataSource = ds.Tables[0];

ws.CreateAutoGenratedColumns();

// turn sort off

for (int i = 0; i < ws.BindColumns.Count; i++)

{

ws.BindColumns[i].EnableSort = false;

}

ws.DataBind();

Aspose.Cells.GridWeb.TableItemStyle style;

for (int i = 0; i < ws.Cells.Count; i++)

{

WebCell cell = ws.Cells[i];

style = cell.GetStyle();

if (cell.Row == 0)

{

style.ForeColor = Color.Red;

style.VerticalAlign = VerticalAlign.Middle;

}

ws.Cells.SetStyle(cell.Row, cell.Column, 1, 1, style);

}

ws.Cells.SetRowHeight(0, Unit.Point(48));

}

}

}

}

Hi,



Thanks for providing us the sample code.

I did test your code snippet. Yes, there is delay on how GridWeb finally renders the data to vertically aligned and make it middle centered, it is by design. Do you need to exclude this little pause and want to directly do the alignment when the data is visible in the active sheet? We may look into it.

Thank you.

I would like the grid to display the column headings vertically aligned centered when it first displays.

It doesn’t look very professional to me to have the column headings top-aligned then a few seconds later have them switch to center-aligned.

Hi,


We will look into it if we can enhance this behavior or we will check if we can provide you some workaround to skip this delay. I have logged a ticket with an id “CELLSNET-41673” for your issue.

We will look into it to figure it out soon.

thank you.

Hi,

We have fixed the issue.

Please download and try this fix: Aspose.Cells for GridWeb.2.7.18.2002 and let us know your feedback.

I downloaded and tried 2.7.18.2002 and I still see the same long delay between when the page is first rendered and when the column headings are formatted as vertical center alignment.

Attached another zip.

Hi,


Please set “var needInitAligmentAdjust=false” in the “acwmain.js” file with latest version/fix Aspose.Cells.GridWeb v2.7.18.2002.

Thank you.

I did what you suggested, set needInitAligmentAdjust=false in acwmain.js.

Now it shows the column headings top aligned and never adjusts them to center aligned as I want. (Before it was coming up top aligned then after about 10 seconds dropping to center aligned. I want it to come up center aligned from the beginning).

I didn't send another set of code because I changed only the one file, acwmain.js. Hopefully you can use the project I sent earlier to test this on it there.

Hi,


I observed the issue as you have mentioned after updating the needInitAlignmentAdjust to false, the alignment is always top alignment. We have logged your comments against your issue id “CELLSNET-41673”. We will look into it if we can enhance it or figure it out.

Thank you.

Hi,


Well, in order do the alignment we need to calculate the cell’s actual height based on the cell content, cell fonts and cell width, it is very complicated and put heavy load on the server side. While being on the client side, we can use the browser’s rendering capability to get actual height in .js. However it is a little time-consuming task, Therefore, in short, we still cannot improve it.

Thanks for your understanding!