Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export to excel from gridview c# format Header text

I am exporting to excel from gridview. Is there any way to format the header text and wrap it in the 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 below to format the header column in excel. but the excel header doesnt gets 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...

like image 296
kk1076 Avatar asked Nov 03 '22 19:11

kk1076


1 Answers

Here is a solution of the formating gridview header.

grdCommon.HeaderRow.CssClass = "header";

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

Using header css class you can add the css properties value.

like image 55
Vishal M. Parikh Avatar answered Nov 09 '22 08:11

Vishal M. Parikh