Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a search button and a text box and gridview with data.when i give value in textbox and press search button it search and give me the value in the gridview.Now i want to export that data in execl.
how would i do it?????????
Posted

Hi,

Please try to use EPPlus. using this we can do it


Regards
Antony
 
Share this answer
 
An oledb is the obvious use here (since you are using ASP.NET):
Reading and Writing Excel using OLEDB[^]
 
Share this answer
 
I Think this will useful to u . . .

C#
protected void btnExport_Click(object sender, EventArgs e)
    {
        btnView_Click(sender, e);
        Response.ClearContent();
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "FileName.csv"));
        Response.ContentType = "application/text";
        grdSell.AllowPaging = false;
        grdSell.DataBind();
        StringBuilder strbldr = new StringBuilder();
        for (int i = 0; i < grdSell.Columns.Count; i++)
        {
            //separting header columns text with comma operator
            strbldr.Append(grdSell.Columns[i].HeaderText + ',');
        }
        //appending new line for gridview header row
        strbldr.Append("\n");
        for (int j = 0; j < grdSell.Rows.Count; j++)
        {
            for (int k = 0; k < grdSell.Columns.Count; k++)
            {
                //separating gridview columns with comma
                strbldr.Append(grdSell.Rows[j].Cells[k].Text + ',');
            }
            //appending new line for gridview rows
            strbldr.Append("\n");
        }
        Response.Write(strbldr.ToString());
        Response.End();
    }
 
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