Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create an excel sheet thought asp.net with using c# . I want full code for this please help me if any body knows
Posted
Updated 2-Jan-12 6:58am
v2
Comments
Rajesh Anuhya 1-Jan-12 6:50am    
No Effort??

Check this out[^].
 
Share this answer
 
Comments
koolprasad2003 2-Jan-12 1:09am    
good link abhinav
Abhinav S 2-Jan-12 1:14am    
Thank you.
NandaKumer 2-Jan-12 23:14pm    
good one
Abhinav S 3-Jan-12 1:53am    
Thanks.
 
Share this answer
 
Hi..,

Have searched in Google, See the Google Result here[^] for your Question..

** Do a Simple Search in Google/CP before posting Question.

Google is your first code friend. :rose:
 
Share this answer
 
C#
#region "   EXPORT TO EXCEL             "
    public void ExportToExcel(DataSet ds)
    {
        try
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=" + HdnMnth.Value + "/2011_Report.doc");
            Response.ContentType = "application/vnd.ms-excel";

            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView gvReport = null;
            TableCell cell1 = null;

            Table tb = new Table();
            TableRow tr1 = null;
            tr1 = new TableRow();

            cell1 = new TableCell();
            cell1.ColumnSpan = ds.Tables.Count + (ds.Tables.Count / 2);
            cell1.Style.Add("color", "Blue");
            cell1.Style.Add("font-weight", "Bold");
            cell1.Text = HdnMnth.Value + "/2011 Montly Report";
            tr1.Cells.Add(cell1);
            tb.Rows.Add(tr1);

            tr1 = new TableRow();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                gvReport = new GridView();
                gvReport.AllowPaging = false;
                gvReport.DataSource = ds.Tables[i];
                gvReport.DataBind();

                cell1 = new TableCell();
                cell1.Style.Add("width", "250px");
                cell1.Controls.Add(gvReport);
                tr1.Cells.Add(cell1);

                cell1 = new TableCell();
                cell1.Text = " ";
                tr1.Cells.Add(cell1);
            }
            tb.Rows.Add(tr1);
            tb.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
        }
    }
    #endregion
 
Share this answer
 
v2
using System.IO;


protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();

Response.AddHeader("content-disposition", "attachment;
filename=FileName.xls");

Response.Charset = "";

// If you want the option to open the Excel file without saving than

// comment out the line below

// Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

public override void VerifyRenderingInServerForm(Control control)
{

// Confirms that an HtmlForm control is rendered for the
specified ASP.NET server control at run time.

}
 
Share this answer
 
Object obj=new Object("Excel.Application");

obj.workbooks.add();
obj.visible=true;
 
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