5

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...

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

From what I see here I think the grdcommon is an "excel" object. If not then the wrapping should be when you send the data to the excel file upon creation.

If it is an "Excel" object then maybe try this link: Wrap Text in excel MSDN

I hope this helps because I haven't touched any interop documents so I can't tell for sure if this is related or not.

And I don't know where you could find these objects but I think this is a step in the right direction.

I hope I helped you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.