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

Exporting to CSV

5 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathap Narravula
Top achievements
Rank 1
Prathap Narravula asked on 14 Jun 2010, 03:33 PM

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"

 

 

GridLines="None" Skin="Outlook" AutoGenerateColumns="False" OnPageIndexChanged="RadGrid1_PageIndexChanged"

 

 

OnPageSizeChanged="RadGrid1_PageSizeChanged" VirtualItemCount="30000" OnSortCommand="RadGrid1_SortCommand"

 

 

OnItemCommand="RadGrid1_ItemCommand" PageSize="5" EnableHeaderContextMenu="True">

 

 

<MasterTableView DataKeyNames="company">

 

 

<PagerStyle AlwaysVisible="True" />

 

 

<Columns>

 

 

<telerik:GridTemplateColumn DataField="company" HeaderText="Code" UniqueName="company">

 

 

<ItemTemplate>

 

 

<asp:LinkButton runat="server" ID="lnkCompany" Text='<%#Eval("company")%>' CommandArgument='<%#Eval("company") +"," +Eval("name")%>'

 

 

OnClick="lnkCompany_Click"></asp:LinkButton>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn HeaderText="Companies ID" DataField="companiesid" UniqueName="companiesid" />

 

 

<telerik:GridBoundColumn HeaderText="UC" DataField="adnocsupplier" UniqueName="adnocsupplier" />

 

 

<telerik:GridBoundColumn HeaderText="Name" DataField="name" UniqueName="name" />

 

 

<telerik:GridBoundColumn HeaderText="Type (A,C,M,P,V)" DataField="type (A,C,M,P,V)"

 

 

UniqueName="type" />

 

 

<telerik:GridBoundColumn HeaderText="Status (A,C,M,P,V)" DataField="status (A,C,M,P,V)"

 

 

UniqueName="status (A,C,M,P,V)" />

 

 

<telerik:GridBoundColumn HeaderText="Rating (C,M,V)" DataField="rating (C,M,V)" UniqueName="rating (C,M,V)" />

 

 

<telerik:GridBoundColumn HeaderText="HSE Score" DataField="hsescore" UniqueName="hsescore" />

 

 

<telerik:GridBoundColumn HeaderText="QA Score" DataField="qascore" UniqueName="qascore" />

 

 

<telerik:GridBoundColumn HeaderText="OPCO" DataField="opco" UniqueName="opco" />

 

 

</Columns>

 

 

<CommandItemSettings ShowExportToCsvButton="True" ShowExportToExcelButton="True" />

 

 

</MasterTableView>

 

 

<ExportSettings HideStructureColumns="True" IgnorePaging="True" OpenInNewWindow="True" />

 

 

</telerik:RadGrid>

Hi,

I am trying to Export Radgrid to CSV.. But problem is getting exporting with html tags.. 

Please help me to ignore the html tags on gridboundcolumns and to export only the required data

Soon reply highly appreciated 

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 14 Jun 2010, 09:15 PM
Hello Prathap,

You could remove the unwanted tags on GridExporting - the easiest approach could be to use regular expressions.
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Csv)
        e.ExportOutput = Regex.Replace(e.ExportOutput, "<(.|\\n)*?>", "");
}

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Prathap Narravula
Top achievements
Rank 1
answered on 15 Jun 2010, 05:41 AM
Dear Daniel,

Thank u very much for u reply and it helped me a lot where i stucked with that point.

One thing is that it is ignoring the '0's in the begining of the numbers..
for example like 000426 as 426 . How can i export with complete number as 000426.

In some of the cells i am getting like  #NAME?  .. How can i ignore this also.


Please help me with soon reply
0
Daniel
Telerik team
answered on 15 Jun 2010, 10:04 AM
Hello Prathap,

You can try to add (manually, in the same event handler) a sign of equality before the problematic strings. I'm afraid this is the only possible workaround.

Example:
="000010251"

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Prathap Narravula
Top achievements
Rank 1
answered on 15 Jun 2010, 10:59 AM
Dear daniel,

I am having the column names Code, Names etc  I am having the data for Code as  000124, 003567, 000003, 003211.
previously i am exporting only 124, 3567, 3, 3211 for Code column.

Please help me to export complete code.

Please modify the above event handler and send me again to my request.

With Regards
0
Daniel
Telerik team
answered on 18 Jun 2010, 11:26 AM
Hello Prathap,

Here is a sample code-snippet:
if (e.ExportType == ExportType.Csv)
{
    e.ExportOutput = "=" + e.ExportOutput.Replace(",\"", ",=\"").Replace("\r\n\"", "\r\n=\"");
}

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Prathap Narravula
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Prathap Narravula
Top achievements
Rank 1
Share this question
or