Click here to Skip to main content
13,249,813 members (87,957 online)
Rate this:
Please Sign up or sign in to vote.
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string dbcon = ConfigurationManager.ConnectionStrings["cn"].ToString();
    public override void VerifyRenderingInServerForm(Control control)
    protected void Button1_Click(object sender, EventArgs e)
        //Excel2007.WorkBook workbook = new Excel2007.WorkBook();
        Response.BufferOutput = false;
        string archiveName = "customer.xls";
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "filename=" + archiveName);
        Response.Charset = "";
      //  workbook.WorkSheets.Add("FirstSheet");
       // workbook.WorkSheets["FirstSheet"].Cells[0, 1].Value = "first";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false; GridView1.DataBind();
        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
    public void ShowData()
        SqlDataAdapter adp = new SqlDataAdapter("select catname,catid,creationdate,pagename from quizcats  ", ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
        DataSet ds = new DataSet();
        GridView1.DataSource = ds;
Posted 18-Dec-12 0:31am
Updated 18-Dec-12 0:34am
vijay cyrus 18-Dec-12 5:34am
Somebody help me out with this code to create a file with .xlsx extension...this code works nicely to create .xls file....but the file with .xlsx extension can't be opened in the excel application....
Abhishek Pant 18-Dec-12 5:35am
whats the problem?
vijay cyrus 18-Dec-12 5:39am
@Abhishek Pant....
I'm not able to create file with extension .xlsx

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please follow and try the link

Export Gridview Data to Excel in ASP.NET[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 26 May 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100