Export to excel from gridview C # format Header text

I export to excel from gridview. Is there a way to format the title text and wrap it in excel ?. My export to excel code as

 grdCommon.Font.Size = FontUnit.XSmall;
 grdCommon.GridLines = GridLines.Both;
 grdCommon.Style["font-family"] = "Arial, Helvetica, sans-serif;";
 grdCommon.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
 grdCommon.HeaderStyle.ForeColor = System.Drawing.Color.White;
 grdCommon.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(80, 124, 209);
 grdCommon.HeaderStyle.Font.Size = 8;
 grdCommon.HeaderStyle.Width = 30;

I tried adding, as shown below, to format the header column in excel. but excel header doesn't get wraped

 grdCommon.HeaderRow.Style.Value = "word-break:break-all;word-wrap:break-word";
 grdCommon.HeaderRow.Cells[0].Wrap = true;

and modified this method

 grdCommon.HeaderRow.Style.Add("background-color", "#FFFFFF"); as 
 grdCommon.HeaderRow.Style.Add("word-wrap","true");

Any suggestions...

+5
source share
2 answers

Here is a solution to the formative gridview header.

grdCommon.HeaderRow.CssClass = "header";

<style>
    .header
    {
        background-color:Silver;
        color:White;
    }
</style>

Using the css header class, you can add the value of the css property.

+2
source

From what I see here, I think grdcommon is an excel object. If not, then there should be packaging when you send data to an excel file when you create it.

Excel, : Excel MSDN

, , - interop, , .

, , , .

, .

0

All Articles