title: how to export .xlsx file C# ASP.NET MVC razor
body: <p>I would like to export data to a <code>.xlsx</code> file, but I can only seem to export to <code>.xls</code>.</p>
  
  <p>What's the easiest way to export a <code>.xlsx</code> file?</p>
  
  <p>This is the code I use to export to a <code>.xls</code> file:</p>
  
  <pre><code>GridView gv = new GridView();
  gv.DataSource = listCatalogue.ToList();
  gv.DataBind();
  Response.ClearContent();
  Response.Buffer = true;
  Response.AddHeader("content-disposition", "attachment; filename=Catalogue.xls");
  Response.ContentType = "application/ms-excel";
  Response.Charset = "";
  StringWriter sw = new StringWriter();
  HtmlTextWriter htw = new HtmlTextWriter(sw);
  gv.RenderControl(htw);
  Response.Output.Write(sw.ToString());
  Response.Flush();
  Response.End();
  </code></pre>