This is a migrated thread and some comments may be shown as answers.

radgrid export to excel not working(the file is corrupt and cannot be opened)

3 Answers 224 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vitaly
Top achievements
Rank 1
Vitaly asked on 16 Jul 2014, 08:20 PM
Good afternoon,
I have following RadGrid in my aspx page:

<telerik:RadGrid ID="EmplReqGrid" runat="server" Skin="Office2010Blue"
GridLines="None" AllowPaging="true" AllowSorting="true"
onexcelmlexportrowcreated="EmplReqGrid_ExcelMLExportRowCreated"
onexcelmlexportstylescreated="EmplReqGrid_ExcelMLExportStylesCreated"
onitemcommand="EmplReqGrid_ItemCommand" onitemcreated="EmplReqGrid_ItemCreated"
onitemdatabound="EmplReqGrid_ItemDataBound"
onneeddatasource="EmplReqGrid_NeedDataSource"
onpageindexchanged="EmplReqGrid_PageIndexChanged"
onpagesizechanged="EmplReqGrid_PageSizeChanged"
onpdfexporting="EmplReqGrid_PdfExporting"
onsortcommand="EmplReqGrid_SortCommand">
<ExportSettings FileName="EmplReqRpt" OpenInNewWindow="true" IgnorePaging="true" ExportOnlyData="true">
<Excel Format="ExcelML" FileExtension="xls"/>
<Pdf FontType="Subset" PaperSize="letter" />
</ExportSettings>
<MasterTableView AutoGenerateColumns="false" AllowMultiColumnSorting="true" >

<Columns>

<telerik:GridBoundColumn HeaderText="Eis-Id" DataField="PRI" UniqueName="PRI" ReadOnly="True" SortExpression="PRI" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>

<telerik:GridBoundColumn HeaderText="ReqNo" DataField="TRKNO" UniqueName="TRKNO" ReadOnly="True" SortExpression="TRKNO" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>

<telerik:GridBoundColumn HeaderText="Term-Id" DataField="TERMID" UniqueName="TERMID" ReadOnly="True" SortExpression="TERMID" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Start Date" DataField="TERMST" UniqueName="TERMST" ReadOnly="true" DataFormatString="{0:MM/dd/yyyy}" SortExpression="TERMST" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="End Date" DataField="TERMEND" UniqueName="TERMEND" ReadOnly="true" DataFormatString="{0:MM/dd/yyyy}" SortExpression="TERMEND" HeaderButtonType="TextButton">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn HeaderText="No of Periods" DataField="NUMP" UniqueName="NUMP" ReadOnly="True" SortExpression="NUMP" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>


<telerik:GridBoundColumn HeaderText="Req Status" DataField="APPRFLAG" UniqueName="APPRFLAG" ReadOnly="True" SortExpression="APPRFLAG" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>


<telerik:GridBoundColumn HeaderText="Rec Status" DataField="STATUS" UniqueName="STATUS" ReadOnly="True" SortExpression="STATUS" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Req Status Date" DataField="FORMDATE" UniqueName="FORMDATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" SortExpression="FORMDATE" HeaderButtonType="TextButton" >
</telerik:GridBoundColumn>

<telerik:GridTemplateColumn HeaderText="Link to Form Button" UniqueName="ButtonColumn">
<ItemTemplate>
<asp:ImageButton ID="ReqFormBtn" ImageUrl="~/Image/update.jpg"
BackColor="transparent" ImageAlign ="Top"
ToolTip="update,re-submit or print the request" runat="server" CommandName="Redirect" />

</ItemTemplate>
</telerik:GridTemplateColumn>

</Columns>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="True" EnablePostBackOnRowClick = "false">
<Selecting AllowRowSelect="false" />
</ClientSettings>
</telerik:RadGrid>

In code behind I press on Export to Excel button:

protected void ExporttoExcel_Click1(object sender, ImageClickEventArgs e)
{
try
{
if (!IsPostBack)
return;
RadGrid ReqInfoGrid = (RadGrid)EmpReqReport.FindItemByValue("EmployeeData").FindControl("EmplReqGrid");
ReqInfoGrid.DataSource = Session["dtGrid"];
ReqInfoGrid.DataBind();
ReqInfoGrid.MasterTableView.ExportToExcel();
}
catch (Exception ex)
{
throw;
}
}

For some reason excel spreadsheet not open instead I am getting error window:
'The file is corrupt and cannot be opened'.

Please help me to resolve this issue.
Thanks so much.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Jul 2014, 05:37 AM
Hi Vitaly,

Please take a look at the following documentation which discuss about this error. It is expected to receive this warning when opening the generated xls file in Microsoft Office 2007.
ExcelML basics

Thanks,
Princy
0
Vitaly
Top achievements
Rank 1
answered on 17 Jul 2014, 01:09 PM
Hi Princy,
thanks for your quick respond.Yes first I am getting this warning message and I click ok and after that I am receiving
error saying "The file is corrupt and cannot be opened".
here is my code in c#:

protected void ExporttoExcel_Click1(object sender, ImageClickEventArgs e)
{
try
{
if (!IsPostBack)
return;
RadGrid ReqInfoGrid = (RadGrid)EmpReqReport.FindItemByValue("EmployeeData").FindControl("EmplReqGrid");
ReqInfoGrid.DataSource = Session["dtGrid"];
ReqInfoGrid.DataBind();
ReqInfoGrid.MasterTableView.ExportToExcel();
}
catch (Exception ex)
{
throw;
}
}
0
Princy
Top achievements
Rank 1
answered on 18 Jul 2014, 06:33 AM
Hi Vitaly,

The cause of this warning message is explained in details in the following blog posts:
MSDN blogs: Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site
Grinn blog: "The file you are trying to open, '[filename]', is in a different format".

Hope this helps.
Thanks,
Princy
Tags
General Discussions
Asked by
Vitaly
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Vitaly
Top achievements
Rank 1
Share this question
or