Click here to Skip to main content
15,886,046 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello,

Can any one help me in "export gridview to Excel file in .xlsx format".
i am able to export griditems to .xls format of excel but not to .xlsx


Thanks
Posted

1 solution

Kindly refer to a similar question asked earlier - Export gridview data to excel 2007 format(xlsx)[^].
I'm sure the answers will help you.
 
Share this answer
 
Comments
jyothivs 3-Feb-14 4:41am    
hello
I am getting below exception

Control 'gvData' of type 'GridView' must be placed inside a form tag with runat=server.

at below line
gvData.RenderControl(htw);

Eventhough i put it inside <form> tagmy aspx code:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>

<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"

Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BOMFileCreation.aspx.cs"

Inherits="UI.Layouts.UI.BOMFileCreation" %>

<html xmlns="http://www.w3.org/1999/xhtml"><body>

<form id="form1" runat="server" title="ATG BOM">

<table cellspacing="0" cellpadding="0" width="100%"> <tr>

<td align="left">Program Name </td> <td>

<asp:TextBox ID="txtPgm" Text = "DSG2014BasicVegWomen10001199" Width="400" runat="server">

</td> </tr> <tr> <td align="left" width="250px">

Program Category Name </td> <td>

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem>--Select--

<asp:ListItem>Women's Vegetarian Program

<asp:ListItem>Women's Uniquely Yours Diabetic Program

<asp:ListItem> Women's Uniquely Yours Silver Program

</td> </tr> <tr>

<td colspan="2" align="right">

<asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnExport_Click"/>  

 

<asp:Button ID="btnApply" runat="server" Text="Apply" OnClick="btnExport_Click"/>  

 

<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnExport_Click"/> 

 

<asp:Button ID="btnExport" runat="server" Text="Export To Excel" OnClick="btnExport_Click"/>

</td> </tr>

</table> <div>

<asp:Label ID="LabelRes" runat="server" Text=""> <table>

<tr> <td>

<asp:Label ID="lblmsg" runat="server" Text=""> </td>

</tr> </table> <table> <tr>

<td>

<asp:GridView ID="gvData" runat="server" CellPadding="4" ForeColor="Black" GridLines="Vertical"

BackColor="White"

BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana"

Font-Size="XX-Small" OnDataBound="gvData_DataBound">

<rowstyle backcolor="#F7F7DE">

<footerstyle backcolor="Tan">

<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />

<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />

<alternatingrowstyle backcolor="White">

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