Export with all data left intact

8 posts, 0 answers
  1. Chris Gårdenberg
    Chris Gårdenberg avatar
    13 posts
    Member since:
    Nov 2008

    Posted 13 Oct 2010 Link to this post

    I have a list that contains images, links, repeaters, and regular labels.

    When I export to excel in HTML-mode (with OnlyData=true), everything except the labels gets stripped.

    Is there someway I can tell the export to export everything, without getting broken images, links and such, everything converted to text, plain text?
  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 15 Oct 2010 Link to this post

    Hello Chris,

    You could leave the ExportOnlyData property to its default value (false) and remove the unwanted elements manually on ItemCreated/ItemDataBound. Please examine the Using ItemCreated/ItemDataBound section in our HTML export help topic.
    Word/Excel export (HTML-based)

    Let me know if you need more specific instructions.

    Best 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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 15 Dec 2010 Link to this post

    Hello Daniel,

    I have the same problem.

    How can I deleted objects HTLM:Submitbutton which are created during the export on Excel File, please ?

    Regards,
    Anne
  5. Chris Gårdenberg
    Chris Gårdenberg avatar
    13 posts
    Member since:
    Nov 2008

    Posted 15 Dec 2010 Link to this post

    Hello Anne,

    I solved this problem by going the hard way around, by making the export of all the data myself.
    I use a component that can read/write excel-files ( http://www.gemboxsoftware.com/GBSpreadsheetFree.htm , we are using this component to read imports and make exports to/from excel).

    With some easy tweaks you can use your datasource and export it to excel in an instant, just define all the columns and write a loop that loops over all the data.

    Or do as Daniel says and use the ItemCreated/ItemDataBound to remove all items you want to remove before the export.

    You'll have more control if you write the export yourself, but it is easier with teleriks already made export-functions.

    But in your event that handles the export, you could always loop over the controls and hide the unwanted ones.

    Here's some code to obtain controls in an controlcollection
    public static IEnumerable<Control> getControls(ControlCollection coll)
    {
    return coll.Cast<Control>().Union(coll.Cast<Control>().SelectMany(c => getControls(c.Controls)));
    }

    And you can use it like
    // Not real code, just putting pseudo-code here.
    static void Page_Load() {
       var controls = getControls(Page.Controls);
    DisableControls(controls);  
    }
      
      
    // This is a function I use to loop over the controls I have to disable them, you could adapt this to remove the controls you want to hide.
    public static void DisableControls(IEnumerable<Control> controls, params string[] excludedIDs)
            {
                foreach (Control ctrl in controls.Where(ctrl2 => !excludedIDs.Any(s => s == ctrl2.ID)))
                {
                    if (ctrl is GridView)
                    {
                        DisableControls(getControls(ctrl.Controls), excludedIDs);
                        foreach (GridViewRow row in ((GridView)ctrl).Rows)
                        {
                            DisableControls(getControls(row.Controls), excludedIDs);
                            foreach (DataControlFieldCell cell in row.Cells)
                            {
                                DisableControls(getControls(cell.Controls), excludedIDs);
                            }
                        }
                    }
                    else if (ctrl is GridViewRow)
                    {
                        DisableControls(getControls(ctrl.Controls), excludedIDs);
                    }
                    else if (ctrl is DataControlFieldCell)
                    {
                        DisableControls(getControls(ctrl.Controls), excludedIDs);
                    }
                    else if (ctrl is Repeater)
                    {
                        DisableControls(getControls(ctrl.Controls), excludedIDs);
                    }
                    else if (ctrl is RepeaterItem)
                    {
                        DisableControls(getControls(ctrl.Controls), excludedIDs);
                    }
                    else if (ctrl is WebControl)
                    {
                        PropertyInfo pi = ctrl.GetType().GetProperty("ReadOnly");
                        if (pi != null)
                            pi.SetValue(ctrl, true, null);
                        else
                            ((WebControl)ctrl).Enabled = false;
                    }
                }
            }
  6. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 20 Dec 2010 Link to this post

    Thank you very much Chris for you quick answer. I'll try it soon.

    Best regards
    Anne
  7. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 23 Dec 2010 Link to this post

    Hello,

    I don't resolved my problem.
    Sometimes on the same web page, the export is well and sometimes it is bad according to filter.
    Sometimes with a same filter, the export is well and sometimes it is bad.
    I don't understand why ?
    I 'll create a ticket.

    Regards
    Anne
  8. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 27 Dec 2010 Link to this post

    Hello Anne,

    Thank you for submitting ticket about this issue. As soon as we find out what is wrong I will post the solution/explanation in this topic.

    Regards,
    Daniel
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  9. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 07 Jan 2011 Link to this post

    I have resolved my problem. A command applied twice.

    My new code :

    Private bFiltre As Boolean = False
      
    Private Sub MyRadGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles MyRadGrid.ItemCommand
            If e.CommandName = "ExportToExcel" Then
                RadFilter1.FireApplyCommand()
                bFiltre = True
            End If
        End Sub
      
        Private Sub MyRadGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyRadGrid.PreRender
            Try
                If bFiltre = False Then
                    RadFilter1.FireApplyCommand()
                Else
                    bFiltre = False
                End If
      
            Catch ex As Exception
      
            End Try
        End Sub

    Than you Chris and Daniel
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017