Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mukund rayate 22 posts 172 karma points
    Jun 21, 2016 @ 09:01
    mukund rayate
    0

    How to create export to excel functionality?

    Hello team , Please guide me on , How to create export to excel functionality . is any video related to this? I am using custom form (not umbraco form) i have a list view of my document type. now i want to export it.

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    Jun 21, 2016 @ 09:03
    Nik
    0

    Hi mukund,

    Could you provide some more information on this? You say you have your own form, do you have your own controller and bits in the back office that allow you to see the results?

    If you have your own controller that the back office is using, you could easily extend your controller to have an action that returns your excel export.

    Nik

  • mukund rayate 22 posts 172 karma points
    Jun 21, 2016 @ 10:03
    mukund rayate
    0

    Yes Nik, I have controller which handle operation on form and save the data. Now i get list view of my all record , on that i want to provide functionality of export.

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Jun 21, 2016 @ 11:29
  • mukund rayate 22 posts 172 karma points
    Jun 21, 2016 @ 12:55
    mukund rayate
    0

    I am using EyeCatchCSVGenerator package for this,

    Got an error Server cannot set content type after HTTP headers have been sent. ? did i miss some thing ?

  • mukund rayate 22 posts 172 karma points
    Jun 23, 2016 @ 07:19
    mukund rayate
    0

    Hi Paul , Now i am trying your approach to export . But every time i get blank file .

    Please look at my code and tel what is wrong ?

    public ActionResult CreateCsv()
        {
            try
            {
                var contactNodes = Umbraco.ContentAtRoot().DescendantsOrSelf("contactPage").FirstOrDefault();
    
    
                List<ExportModel> products = new List<ExportModel>();
    
                foreach (var Item in contactNodes.Children)
                {
                    ExportModel ContactListItem = new ExportModel();
                    ContactListItem.Id = Item.Id;
                    ContactListItem.Name = Item.GetPropertyValue<string>("contactName");
                    ContactListItem.Email = Item.GetPropertyValue<string>("email");
                    ContactListItem.Telephone = Item.GetPropertyValue<string>("telphone");
                    ContactListItem.Comment = Item.GetPropertyValue<string>("comments");
                    ContactListItem.ContactDate = Item.GetPropertyValue<string>("contactDate");
                    ContactListItem.IpAddress = Item.GetPropertyValue<string>("iPAddress");
                    products.Add(ContactListItem);
                }
    
                List<ExportModel> EMs = products;
    
    
                var grid = new GridView();
                grid.DataSource = EMs;
                grid.DataBind();
    
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=Contact.xls");
                Response.ContentType = "application/ms-excel";
    
                Response.Charset = "";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
    
                grid.RenderControl(htw);
    
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();             
                ViewBag.thankyouexportedstr = "Record are explorted successfully";
    
            }
            catch (Exception e)
            {
                ViewBag.thankyouexportedstr = "Excetion occured during export" + e.StackTrace  ;
                throw;
            }           
            return PartialView("ThankYouExported");
        }      
    
Please Sign in or register to post replies

Write your reply to:

Draft