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

Export

8 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 17 Oct 2008, 02:07 AM
I try to export a simple grid without any success

to excel - it only give me the current page when ignorpaging = false and none when ignorepaging = true

to pdf - it give me an error of unsupported file type.

How do I resolve this?

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Oct 2008, 06:19 AM
Hello Raymond,

Can you provide a bit more info how to reproduce this? Or can you reproduce this on our examples:
http://demos.telerik.com/aspnet/Prometheus/Grid/Examples/GeneralFeatures/Exporting/DefaultCS.aspx
http://demos.telerik.com/aspnet/Prometheus/Grid/Examples/GeneralFeatures/PdfExport/DefaultCS.aspx

Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 1
answered on 17 Oct 2008, 11:41 AM
Hi Raymond,

Try removing the paging functionality for the Grid in the Export button's click event and see whether it is working.

CS:
 protected void Button1_Click(object sender, EventArgs e) 
    { 
        RadGrid1.AllowPaging = false
        RadGrid1.Rebind(); 
        RadGrid1.ExportSettings.OpenInNewWindow = true
        RadGrid1.MasterTableView.ExportToExcel(); 
    } 



Thanks
Shinu.
0
Raymond
Top achievements
Rank 1
answered on 17 Oct 2008, 01:04 PM
The suggested solution is not working too.

The page is as follows

 

<telerik:RadGrid ID="rgAccountXact" DataSourceID="odsAccountXact" AllowSorting="True"

 

 

runat="server" OnItemCreated="rgAccountXact_ItemCreated" OnItemDataBound="rgAccountXact_ItemDataBound"

 

 

AutoGenerateColumns="False" AllowPaging="True" PageSize="19"

 

 

CellPadding="5" CellSpacing="5" Skin="Office2007">

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

<MasterTableView ShowFooter="False" Width="100%" DataKeyNames="idAcctXact" CommandItemDisplay="Top">

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibEdit" runat="server" ImageUrl="~/Images/Edit.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn UniqueName="AcctDate" HeaderText="Date" SortExpression="AcctDate">

 

 

<ItemTemplate>

 

<%

# FormatDate( Eval("AcctDate").ToString())%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="Beneficiary" HeaderText="Shopper">

 

 

<ItemTemplate>

 

<%

# Eval("Beneficiary")%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" UniqueName="Amount"

 

 

ItemStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn DataField="Notes" HeaderText="Note" UniqueName="Notes" />

 

 

<telerik:GridTemplateColumn UniqueName="TemplateDeleteColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/Images/trash.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

<CommandItemTemplate>

 

 

<div style="padding:10px 0px;">

 

 

&nbsp;&nbsp;&nbsp;

 

 

<asp:ImageButton ID="ibAdd" runat="server" AlternateText="Add new Account xact" ImageUrl="~/Images/Add.gif"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

&nbsp&nbsp;

 

 

<asp:LinkButton ID="lbAdd" runat="server" Text="New Account Xact" ToolTip="Add New Account Xact"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

</div>

 

 

</CommandItemTemplate>

 

 

</MasterTableView>

 

 

<ClientSettings EnableRowHoverStyle="true">

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

 

<asp:ObjectDataSource ID="odsAccountXact" runat="server" TypeName="RaymondApp.AccountXact"

 

 

SelectMethod="Search" SelectCountMethod="SearchCount" EnablePaging="True" SortParameterName="sortBy"

 

 

MaximumRowsParameterName="pageSize" StartRowIndexParameterName="firstRow"

 

 

OldValuesParameterFormatString="original_{0}">

 

 

<SelectParameters>

 

 

<asp:Parameter Name="firstRow" Type="Int32" DefaultValue="0" />

 

 

<asp:Parameter Name="pageSize" Type="Int32" DefaultValue="10" />

 

 

<asp:Parameter Name="sortBy" Type="String" DefaultValue="AcctDate DESC" />

 

 

<asp:Parameter Name="idAcctXact" Type="Int32" />

 

 

<asp:Parameter Name="acctDate" Type="DateTime" />

 

 

<asp:Parameter Name="idGroupType" Type="Int32" />

 

 

<asp:Parameter Name="xactType" Type="String" />

 

 

<asp:Parameter Name="beneficiary" Type="String" />

 

 

<asp:Parameter Name="amount" Type="Decimal" />

 

 

<asp:Parameter Name="idAccount" Type="Int32" DefaultValue="1" />

 

 

<asp:Parameter Name="source" Type="String" />

 

 

<asp:Parameter Name="relatedID" Type="Int32" />

 

 

<asp:Parameter Name="notes" Type="String" />

 

 

<asp:Parameter Name="checkNo" Type="String" />

 

 

<asp:Parameter Name="reconcile" Type="Boolean" />

 

 

<asp:Parameter Name="reconciled" Type="Int32" />

 

 

<asp:Parameter Name="dateReconciled" Type="DateTime" />

 

 

<asp:Parameter Name="formatType" Type="String" />

 

 

</SelectParameters>

 

 

</asp:ObjectDataSource>

 

<

 

asp:Button ID="btn" runat="server" Text="export" OnClick="ibExcel_Click" />


code behind on click event

 

 

protected void ibExcel_Click(object sender, EventArgs e)

 

{

 

try

 

 

 

 

{

 

//rgTools.PageSize = rgTools.MasterTableView.VirtualItemCount;

 

 

 

 

rgAccountXact.AllowPaging =

false;

 

rgAccountXact.Rebind();

rgAccountXact.ExportSettings.OpenInNewWindow =

true;

 

 

//rgAccountXact.ExportSettings.IgnorePaging = true;

 

 

 

 

 

//rgAccountXact.ExportSettings.ExportOnlyData = true;

 

 

 

 

 

//rgTools.MasterTableView.ExportToPdf();

 

 

 

 

 

////ConfigureExport();

 

 

 

 

rgAccountXact.MasterTableView.ExportToExcel();

 

//rgTools.AllowPaging = true;

 

 

 

 

 

//rgTools.Rebind();

 

 

 

 

}

 

catch (Exception ex)

 

{

}

}

I cannot export any in pdf (no matter the ignorpaging is set or not) and in excel (only work on ignorepaging = false)

0
Raymond
Top achievements
Rank 1
answered on 17 Oct 2008, 01:04 PM
The suggested solution is not working too.

The page is as follows

 

<telerik:RadGrid ID="rgAccountXact" DataSourceID="odsAccountXact" AllowSorting="True"

 

 

runat="server" OnItemCreated="rgAccountXact_ItemCreated" OnItemDataBound="rgAccountXact_ItemDataBound"

 

 

AutoGenerateColumns="False" AllowPaging="True" PageSize="19"

 

 

CellPadding="5" CellSpacing="5" Skin="Office2007">

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

<MasterTableView ShowFooter="False" Width="100%" DataKeyNames="idAcctXact" CommandItemDisplay="Top">

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibEdit" runat="server" ImageUrl="~/Images/Edit.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn UniqueName="AcctDate" HeaderText="Date" SortExpression="AcctDate">

 

 

<ItemTemplate>

 

<%

# FormatDate( Eval("AcctDate").ToString())%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="Beneficiary" HeaderText="Shopper">

 

 

<ItemTemplate>

 

<%

# Eval("Beneficiary")%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" UniqueName="Amount"

 

 

ItemStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn DataField="Notes" HeaderText="Note" UniqueName="Notes" />

 

 

<telerik:GridTemplateColumn UniqueName="TemplateDeleteColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/Images/trash.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

<CommandItemTemplate>

 

 

<div style="padding:10px 0px;">

 

 

&nbsp;&nbsp;&nbsp;

 

 

<asp:ImageButton ID="ibAdd" runat="server" AlternateText="Add new Account xact" ImageUrl="~/Images/Add.gif"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

&nbsp&nbsp;

 

 

<asp:LinkButton ID="lbAdd" runat="server" Text="New Account Xact" ToolTip="Add New Account Xact"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

</div>

 

 

</CommandItemTemplate>

 

 

</MasterTableView>

 

 

<ClientSettings EnableRowHoverStyle="true">

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

 

<asp:ObjectDataSource ID="odsAccountXact" runat="server" TypeName="RaymondApp.AccountXact"

 

 

SelectMethod="Search" SelectCountMethod="SearchCount" EnablePaging="True" SortParameterName="sortBy"

 

 

MaximumRowsParameterName="pageSize" StartRowIndexParameterName="firstRow"

 

 

OldValuesParameterFormatString="original_{0}">

 

 

<SelectParameters>

 

 

<asp:Parameter Name="firstRow" Type="Int32" DefaultValue="0" />

 

 

<asp:Parameter Name="pageSize" Type="Int32" DefaultValue="10" />

 

 

<asp:Parameter Name="sortBy" Type="String" DefaultValue="AcctDate DESC" />

 

 

<asp:Parameter Name="idAcctXact" Type="Int32" />

 

 

<asp:Parameter Name="acctDate" Type="DateTime" />

 

 

<asp:Parameter Name="idGroupType" Type="Int32" />

 

 

<asp:Parameter Name="xactType" Type="String" />

 

 

<asp:Parameter Name="beneficiary" Type="String" />

 

 

<asp:Parameter Name="amount" Type="Decimal" />

 

 

<asp:Parameter Name="idAccount" Type="Int32" DefaultValue="1" />

 

 

<asp:Parameter Name="source" Type="String" />

 

 

<asp:Parameter Name="relatedID" Type="Int32" />

 

 

<asp:Parameter Name="notes" Type="String" />

 

 

<asp:Parameter Name="checkNo" Type="String" />

 

 

<asp:Parameter Name="reconcile" Type="Boolean" />

 

 

<asp:Parameter Name="reconciled" Type="Int32" />

 

 

<asp:Parameter Name="dateReconciled" Type="DateTime" />

 

 

<asp:Parameter Name="formatType" Type="String" />

 

 

</SelectParameters>

 

 

</asp:ObjectDataSource>

 

<

 

asp:Button ID="btn" runat="server" Text="export" OnClick="ibExcel_Click" />


code behind on click event

 

 

protected void ibExcel_Click(object sender, EventArgs e)

 

{

 

try

 

 

 

 

{

 

//rgTools.PageSize = rgTools.MasterTableView.VirtualItemCount;

 

 

 

 

rgAccountXact.AllowPaging =

false;

 

rgAccountXact.Rebind();

rgAccountXact.ExportSettings.OpenInNewWindow =

true;

 

 

//rgAccountXact.ExportSettings.IgnorePaging = true;

 

 

 

 

 

//rgAccountXact.ExportSettings.ExportOnlyData = true;

 

 

 

 

 

//rgTools.MasterTableView.ExportToPdf();

 

 

 

 

 

////ConfigureExport();

 

 

 

 

rgAccountXact.MasterTableView.ExportToExcel();

 

//rgTools.AllowPaging = true;

 

 

 

 

 

//rgTools.Rebind();

 

 

 

 

}

 

catch (Exception ex)

 

{

}

}

I cannot export any in pdf (no matter the ignorpaging is set or not) and in excel (only work on ignorepaging = false)

0
Raymond
Top achievements
Rank 1
answered on 17 Oct 2008, 01:04 PM
The suggested solution is not working too.

The page is as follows

 

<telerik:RadGrid ID="rgAccountXact" DataSourceID="odsAccountXact" AllowSorting="True"

 

 

runat="server" OnItemCreated="rgAccountXact_ItemCreated" OnItemDataBound="rgAccountXact_ItemDataBound"

 

 

AutoGenerateColumns="False" AllowPaging="True" PageSize="19"

 

 

CellPadding="5" CellSpacing="5" Skin="Office2007">

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

<MasterTableView ShowFooter="False" Width="100%" DataKeyNames="idAcctXact" CommandItemDisplay="Top">

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibEdit" runat="server" ImageUrl="~/Images/Edit.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn UniqueName="AcctDate" HeaderText="Date" SortExpression="AcctDate">

 

 

<ItemTemplate>

 

<%

# FormatDate( Eval("AcctDate").ToString())%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="Beneficiary" HeaderText="Shopper">

 

 

<ItemTemplate>

 

<%

# Eval("Beneficiary")%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" UniqueName="Amount"

 

 

ItemStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn DataField="Notes" HeaderText="Note" UniqueName="Notes" />

 

 

<telerik:GridTemplateColumn UniqueName="TemplateDeleteColumn">

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/Images/trash.gif" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

<CommandItemTemplate>

 

 

<div style="padding:10px 0px;">

 

 

&nbsp;&nbsp;&nbsp;

 

 

<asp:ImageButton ID="ibAdd" runat="server" AlternateText="Add new Account xact" ImageUrl="~/Images/Add.gif"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

&nbsp&nbsp;

 

 

<asp:LinkButton ID="lbAdd" runat="server" Text="New Account Xact" ToolTip="Add New Account Xact"

 

 

OnClientClick="return ShowInsertXact();" />

 

 

</div>

 

 

</CommandItemTemplate>

 

 

</MasterTableView>

 

 

<ClientSettings EnableRowHoverStyle="true">

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

 

<asp:ObjectDataSource ID="odsAccountXact" runat="server" TypeName="RaymondApp.AccountXact"

 

 

SelectMethod="Search" SelectCountMethod="SearchCount" EnablePaging="True" SortParameterName="sortBy"

 

 

MaximumRowsParameterName="pageSize" StartRowIndexParameterName="firstRow"

 

 

OldValuesParameterFormatString="original_{0}">

 

 

<SelectParameters>

 

 

<asp:Parameter Name="firstRow" Type="Int32" DefaultValue="0" />

 

 

<asp:Parameter Name="pageSize" Type="Int32" DefaultValue="10" />

 

 

<asp:Parameter Name="sortBy" Type="String" DefaultValue="AcctDate DESC" />

 

 

<asp:Parameter Name="idAcctXact" Type="Int32" />

 

 

<asp:Parameter Name="acctDate" Type="DateTime" />

 

 

<asp:Parameter Name="idGroupType" Type="Int32" />

 

 

<asp:Parameter Name="xactType" Type="String" />

 

 

<asp:Parameter Name="beneficiary" Type="String" />

 

 

<asp:Parameter Name="amount" Type="Decimal" />

 

 

<asp:Parameter Name="idAccount" Type="Int32" DefaultValue="1" />

 

 

<asp:Parameter Name="source" Type="String" />

 

 

<asp:Parameter Name="relatedID" Type="Int32" />

 

 

<asp:Parameter Name="notes" Type="String" />

 

 

<asp:Parameter Name="checkNo" Type="String" />

 

 

<asp:Parameter Name="reconcile" Type="Boolean" />

 

 

<asp:Parameter Name="reconciled" Type="Int32" />

 

 

<asp:Parameter Name="dateReconciled" Type="DateTime" />

 

 

<asp:Parameter Name="formatType" Type="String" />

 

 

</SelectParameters>

 

 

</asp:ObjectDataSource>

 

<

 

asp:Button ID="btn" runat="server" Text="export" OnClick="ibExcel_Click" />


code behind on click event

 

 

protected void ibExcel_Click(object sender, EventArgs e)

 

{

 

try

 

 

 

 

{

 

//rgTools.PageSize = rgTools.MasterTableView.VirtualItemCount;

 

 

 

 

rgAccountXact.AllowPaging =

false;

 

rgAccountXact.Rebind();

rgAccountXact.ExportSettings.OpenInNewWindow =

true;

 

 

//rgAccountXact.ExportSettings.IgnorePaging = true;

 

 

 

 

 

//rgAccountXact.ExportSettings.ExportOnlyData = true;

 

 

 

 

 

//rgTools.MasterTableView.ExportToPdf();

 

 

 

 

 

////ConfigureExport();

 

 

 

 

rgAccountXact.MasterTableView.ExportToExcel();

 

//rgTools.AllowPaging = true;

 

 

 

 

 

//rgTools.Rebind();

 

 

 

 

}

 

catch (Exception ex)

 

{

}

}

I cannot export any in pdf (no matter the ignorpaging is set or not) and in excel (only work on ignorepaging = false)

0
Nikolay Rusev
Telerik team
answered on 20 Oct 2008, 02:05 PM
Hello Raymond,

Unfortunately I don't see anything in your code that might cause exporting of RadGrid to fail.
For your convenience I prepared a small example demonstrating RadGrid export to Excel and Pdf. Part of the RadGrid columns definition is as yours posted in this forum thread.

Please find the project and give it a try. If you are still having issues with your project, I suggest you open a formal support ticket and send us a runnable example that replicates the issue. Thus we'll be able to help you further.

Best regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Omarr
Top achievements
Rank 1
answered on 24 Oct 2008, 03:30 PM

Try this function. Change the pagesize to the total no. of rows of the datatable. This will solve your problem.

public void Export2Excel(Telerik.Web.UI.RadGrid gridViewName, int TotalCount, string WorkBookName)
{
 
 gridViewName.MasterTableView.PageSize = TotalCount;
 gridViewName.ExportSettings.OpenInNewWindow = true;
 gridViewName.ExportSettings.FileName = WorkBookName;
 gridViewName.ExportSettings.IgnorePaging = true;
 gridViewName.MasterTableView.ExportToExcel();

}

 

 

0
Lan
Top achievements
Rank 1
answered on 02 Nov 2011, 05:59 PM
If you use object datasource, try this

protected void ods_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (0 == e.Arguments.MaximumRows)
{
e.Arguments.MaximumRows = int.MaxValue;
}

}
Tags
Grid
Asked by
Raymond
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Shinu
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Omarr
Top achievements
Rank 1
Lan
Top achievements
Rank 1
Share this question
or