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

export to csv

4 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lm
Top achievements
Rank 1
lm asked on 15 Jul 2013, 06:28 PM
I have a radgrid with mostly template columns...I have added export feature to the grid, export to pdf works fine with the footer details but with csv export footer is missing I am looking for group footer and grid footer data. Is it possible if so please guide me. thank you

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jul 2013, 09:09 AM
Hi Im,

Please try the following example code snippet to export footer data.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  ShowFooter="True" ShowGroupFooter="true" OnGridExporting="RadGrid1_GridExporting">
    <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true">
    </ExportSettings>
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToCsvButton="true" />
        <Columns>
            <telerik:GridBoundColumn HeaderText="Unit Price" DataField="UnitPrice" UniqueName="UnitPrice"
                Aggregate="Sum">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="TemplateColumn">
                <HeaderTemplate>
                    Quantity
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Quantity")%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
   {
     if (e.ExportType == ExportType.Csv)
     {
       string footer = "";
       GridFooterItem footerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
       foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
       if (column.Visible)
       footer += String.Format("\"{0}\",", footerItem[column.UniqueName].Text.Replace(" ", ""));
       e.ExportOutput += footer;
       }
   }

Hope this helps.

Thanks,
Shinu
0
lm
Top achievements
Rank 1
answered on 16 Jul 2013, 01:22 PM
I believe the code provided by you would help me to get the gridfooter but I need to export the group footer as well in to csv file.

Also I get file error when I export to Excel I researching I understood that xslx is not supported by radgrid, even saving the file as xls and opening it later did not help me. any options please let me know. thank you
0
lm
Top achievements
Rank 1
answered on 16 Jul 2013, 09:17 PM
I managed to export to excel using excel format excelml, similar to csv the group footers are not exported, could you please help me to find a solution.
0
Kostadin
Telerik team
answered on 18 Jul 2013, 11:29 AM
Hello Lavanua,

Would recommend you to check out the following forum post.
Radgrid doesnt export Grid-Footer to Excel (ExcelML)
ExcelML Export with aggregates in groupfooter

Since CSV file is a plain text, it does not support footer as well, so you have to add the footer manually. Shinu's suggestion demonstrates a possible solution how this could be achieved.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
lm
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
lm
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or