MVVM Excel Export

6 posts, 0 answers
  1. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 21 Oct 2015 Link to this post

    I currently implemented Excel Export behind code, I'm trying to have it be implemented in the ViewModel Instead. How abouts would I do that?

     

     

     

            private void MenuItem_OnClick(object sender, RoutedEventArgs e)
            {
                try
                {
                    string content;

                    var extension = "xml";
                    content = DrillThroughGridView.ToExcelML(true);

                    string path = String.Format("Export.{0}", extension);

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    using (FileStream fs = File.Create(path))
                    {
                        Byte[] info = Encoding.Default.GetBytes(content);
                        fs.Write(info, 0, info.Length);
                    }

                    Process.Start(path);
                }
                catch (Exception)
                {
                    Notification.Error("Process Busy", "Please exit excel instance.");
                }
            }​

     

     

  2. Petya
    Admin
    Petya avatar
    983 posts

    Posted 22 Oct 2015 Link to this post

    Hello Minh,

    You can create a command in your view model and bind it to the MenuItem's Command property, so it will be executed when the item is clicked.

    Regards,
    Petya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 28 Oct 2015 Link to this post

    Hi Petya, 

    I the viewmodel command part is relatively easy, how would I get "content = DrillThroughGridView.ToExcelML(true)" on the ViewModel side? 
  4. Petya
    Admin
    Petya avatar
    983 posts

    Posted 30 Oct 2015 Link to this post

    Hi Minh,

    You can pass the RadGridView instance as a parameter to the command. There are several examples using this approach in our demos, for example, Customizing ExcelML export. I also encourage you to take a look at the ExportToXlsx option we introduced in one of our recent releases in this article and the Exporting to Xlsx and Pdf demo.

    Regards,
    Petya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Marco
    Marco avatar
    1 posts
    Member since:
    Aug 2017

    Posted 23 Aug in reply to Petya Link to this post

    Dear all,

     

    can you please help me to find out one of these examples?

  6. Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 25 Aug Link to this post

    Hi Marco,

    As Petya suggested you can download the WPF Control Demo application. Then you can navigate to the GridView section and take a look at the Exporting and Printing demos.

    There is a Silverlight online version of this application. Here is a link for the Customizing ExcelML export demo.

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top