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

MVVM Excel Export

5 Answers 414 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 21 Oct 2015, 01:53 PM

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.");
            }
        }​

 

 

5 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 22 Oct 2015, 04:08 PM
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
0
Minh
Top achievements
Rank 1
answered on 28 Oct 2015, 01:46 PM
Hi Petya, 

I the viewmodel command part is relatively easy, how would I get "content = DrillThroughGridView.ToExcelML(true)" on the ViewModel side? 
0
Petya
Telerik team
answered on 30 Oct 2015, 02:59 PM
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
0
Marco
Top achievements
Rank 1
answered on 23 Aug 2017, 07:53 AM

Dear all,

 

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

0
Dinko | Tech Support Engineer
Telerik team
answered on 25 Aug 2017, 12:17 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Minh
Top achievements
Rank 1
Answers by
Petya
Telerik team
Minh
Top achievements
Rank 1
Marco
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or