Click here to Skip to main content
15,913,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii......

alignment problem in export to excel?

i listing the codes i used,


C#
private void ExportGridView()
    {
        //To make the last row unbold//
        //int j = gvScoreList.Rows[0].Cells.Count;
        int i = gvMark.Rows.Count;
        //foreach (GridViewRow row in gvSalaryStatement.Rows)
        //{
        //gvFeeReport.Rows[i - 1].Cells[j - 2].Text = "Total";
        //}
        if (i > 0)
        {
            btnExportToWord.Visible = true;
            btnExportToExcel.Visible = true;
            string attachment = "attachment; filename=File.xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            //gvScoreList.RenderControl(htw);
            //lblFailed.RenderControl(htw);
            pnlExport.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
        else
        {
            btnExportToWord.Visible = false;
            btnExportToExcel.Visible = false;
        }
    }
Posted
Updated 28-Jul-11 2:07am
v3
Comments
[no name] 28-Jul-11 8:08am    
The HTML portion was useless and distracting.

What problem are you encountering?
Ashika s 4-Aug-11 0:19am    
i need any other methos also.............
WmCPayne 3-Jul-17 5:15am    
Take a look at this article. With that approach you'll create a real Excel file, unlike that code that you're using which generates a HTML file that is just named as "File.xls".
Also here you can find another example of exporting to excel in asp.net.

1 solution

Set Gridview Width Proper. after setting gridview width same u see in the Excel
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900