Export to Excel

17 posts, 0 answers
  1. Asra
    Asra avatar
    22 posts
    Member since:
    May 2009

    Posted 02 Jun 2009 Link to this post

    Hi ALL,
                    Iam using Export to Excel for the RadGrid. in code behind iam writing like this

    RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.

    GridExcelExportFormat.ExcelML;

     

    RadGrid1.ExportSettings.ExportOnlyData =

    true;

     

    RadGrid1.MasterTableView.ExportToExcel();

    On  RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML; it is giving me error as object Reference is not set.

    Can any one pls let me know why it is giving that error.

    Regards,
    asra

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 02 Jun 2009 Link to this post

    Hello Asra,

    I followed your scenario in order to replicate the issue but to no avail.
    Please find attached a simple runnable application that demonstrates the needed approach. Give it a try and let me know if it works for you.

    Best wishes,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 06 Apr 2010 Link to this post

    i'm not able to get this export to excel to work.
    i'm not getting expected behaviour. what is happening however (and this is the same behaviour in all browsers) is the grid is simply reloaded or rerendered in the same browser window but all command item icons are gone, all icons i use in my grid are gone and replaced by their tooltip text, and paging functionality is gone and only one page of data is visible.

    I am using version 2009.3.1314.35.

    This is the code in my ItemCommand event for exporting to excel:

                        case "ExportToExcel":
                            this.InactiveUnitGrid.ExportSettings.OpenInNewWindow = true;
                            this.InactiveUnitGrid.ExportSettings.ExportOnlyData = true;
                            this.InactiveUnitGrid.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
                            this.InactiveUnitGrid.MasterTableView.ExportToExcel();
                            break;

    Update. I just tried to handle these grid events but they never fired. Breakpoints were never hit.

                                                                                OnExcelMLExportStylesCreated="InactiveUnitGrid_ExcelMLExportStylesCreated"
                                                                                OnExcelMLExportRowCreated="InactiveUnitGrid_ExcelMLExportRowCreated"

            protected void mygridd_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
            {
                if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)
                {
                    if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U"))
                    {
                        e.Row.Cells[0].StyleValue = "MyCustomStyle";
                    }
                }
            }

            protected void mygrid_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e)
            {
                foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles)
                {
                    if (style.Id == "headerStyle")
                    {
                        style.FontStyle.Bold = true;
                        style.FontStyle.Color = System.Drawing.Color.Gainsboro;
                        style.InteriorStyle.Color = System.Drawing.Color.Wheat;
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                    }
                    else if (style.Id == "itemStyle")
                    {
                        style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke;
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                    }
                    else if (style.Id == "alternatingItemStyle")
                    {
                        style.InteriorStyle.Color = System.Drawing.Color.LightGray;
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                    }
                }

                Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle");
                myStyle.FontStyle.Bold = true;
                myStyle.FontStyle.Italic = true;
                myStyle.InteriorStyle.Color = System.Drawing.Color.Gray;
                myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                e.Styles.Add(myStyle);
            }
  5. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 06 Apr 2010 Link to this post

    I have a column that is used only to display a command button used for editing details.
    How do I exclude this column from exporting to excel?
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Apr 2010 Link to this post

    Hello,

    Please, refer to the help article below, for more information about how to achieve your goal.
    ExcelML export

    Regards,
    Pavlina
    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.
  7. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    What might it mean then if the ExcelMLExportRowCreated or ExcelMLExportStylesCreated never get fired?
  8. Bruno
    Bruno avatar
    105 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    Hi

    this is Bruno amd oing project with Telerik control

    "i'm not able to get this export to excel to work.
    i'm not getting expected behaviour. what is happening however (and this is the same behaviour in all browsers) is the grid is simply reloaded or rerendered in the same browser window but all command item icons are gone, all icons i use in my grid are gone and replaced by their tooltip text, and paging functionality is gone and only one page of data is visible."
    i was get the same behaving with ajax enable - stop ajaxing and try again

    What might it mean then if the ExcelMLExportRowCreated or ExcelMLExportStylesCreated never get fired?
    wire the gridexporting event and checking the export type - am bet that you are use the mistake type

    exsample:
        void BrunoGridView_GridExporting(object source, GridExportingArgs e)
        {
            //check e.ExportType
        }

    sorry for my bed english

    Bruno
  9. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    Bruno, thanks for the reply!
    Right the ajaxing! oi.
    It must be that because Grid_GridExporting isn`t firing either. Is there a way to turn off ajaxing only when I want to export to Excel then.... hmmmmmmmmmmmm.

    argh....
    I`m using Update Panels!
  10. Bruno
    Bruno avatar
    105 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    Hi

    this is Bruno and am happy that help

    you can use client site code as catch on request start event
    function ajax_manager_requeststart(sender, args)
    {
       if (args.get_eventTarget().indexOf("myexportbutonid") >= 0)
    {
           args.set_enableAjax(false); }
       }

    i attach this cod on ajaxmanager client start request event

    Bruno
  11. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    that might work with ajax manager.

    the UI i`m working on is update panel driven.

    i doubt there`s anything i can do with update panels and i don`t really want to refactor to use an ajax manager for this particular UI at this point....

    any suggestions from the telerik folké

  12. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    Okay, cool http://www.telerik.com/help/aspnet-ajax/grdexportwithajax.html
    I have export working. But I'm still having some issues.
    The excel file gets saved but I only get one page of data. And the column that contains a button is being included as text that says something like "Click to Edit" for each row....

    I configure the export thus:
                UnitsGrid.ExportSettings.ExportOnlyData = true;
                UnitsGrid.ExportSettings.IgnorePaging = false;
                UnitsGrid.ExportSettings.OpenInNewWindow = true;

    I try hiding the edit icon button column 
     this.InactiveUnitGrid.MasterTableView.Columns[0].Visible = false;

    And try hiding command item headers
                foreach (GridItem commandItem in this.InactiveUnitGrid.MasterTableView.GetItems(GridItemType.CommandItem))
                {
                    commandItem.Visible = false;
                }

    I've set the excel format to ExcelML as opposed to HTML. That caused the InactiveUnitGrid_ExcelMLExportRowCreated and InactiveUnitGrid_ExcelMLExportStylesCreated to fire.

    I can catch a breakpoint in those events. The code is changing style attributes which don't get reflected in the excel output.
    The grid does get rebound but paging is not ignored (only the first 50 rows of the 1st page are exported)...
  13. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 08 Apr 2010 Link to this post

    arhg. changing pages breaks the export functionality. it puts me back in the state i was before i solved the ajax problem....
    the export only works on page one! anyone else run into this?
  14. Bruno
    Bruno avatar
    105 posts
    Member since:
    Mar 2008

    Posted 14 Apr 2010 Link to this post

    hi

    this is Bruno

    i never see that problem in normal condition
     do yo use custom pagings?

    i will ask my colleage he may know this ....
  15. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 14 Apr 2010 Link to this post

    just using regular standard pagings.

    thanks
  16. Bruno
    Bruno avatar
    105 posts
    Member since:
    Mar 2008

    Posted 19 Apr 2010 Link to this post

    Bruno's colleague here

    I'm not quite familiar with this particular problem. Looking at the description of the problem I think it might be a databinding issue. One of the most useful extras of RadGrid is the needatasource binding - you will hardly have any databinding problems using it.

    Sorry for the delay but we are busy working on a nasty internal project right now
  17. Zinith Patel
    Zinith Patel avatar
    4 posts
    Member since:
    Jan 2010

    Posted 12 Aug 2010 Link to this post

    Hello,

    I am also having such kind of issue. 
    As per my requirement, I have to show hide column at runtime. So, while exporting if that column is visible then it should be exported.
    This is working fine if I select dgUnPart.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.Html. But, when I select dgUnPart.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML then it does not export that column.

    Kindly do needful.

  18. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 12 Aug 2010 Link to this post

    Hello Zinith,

    To export in ExcelML format the ExportOnlyData property should be set to true. Review this help article for more information:
    http://www.telerik.com/help/aspnet-ajax/grid-excelml-export.html

    All the best,
    Pavlina
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017