We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Export multiple controls in a window to excel

Thread ID:

Created:

Updated:

Platform:

Replies:

119509 Jul 2,2015 05:23 AM UTC Jul 3,2015 02:28 AM UTC WPF 1
loading
Tags: SfDataGrid
Senthil Ramanathan
Asked On July 2, 2015 05:23 AM UTC

One of my windows has a combination of grids (sfdatagrid) and charts (sfchart).

How can I export them to a single excel worksheet..?

Akila Rajaram [Syncfusion]
Replied On July 3, 2015 02:28 AM UTC

Hi Senthil ,

Thank you for using Syncfusion Products.

We analyzed your query . We regret to  inform you  that we don’t have direct support to export SfChart to Excel . But you can overcome this by saving the SfChart  as an image , then you can export it as image by specifying  row and column index of specified worksheet  explicitly . With the help of  ExportToExcel() helper method  ,you can export the SfDataGrid to Excel . We  have  prepared the sample based on your requirement . Please find the sample from the following location ,

Sample :  http://www.syncfusion.com/downloads/support/forum/119509/ze/SfDataGrid_Sample_119509-1475285012

Please refer the following code example ,

C#:

private void btn_Click(object sender, RoutedEventArgs e)

{

    if (grid == null) return;

    try

    {

        chart.Save("temp.jpg");

        string jpgimage = "temp.jpg";

        ExcelExportingOptions option = new ExcelExportingOptions();              

        option.ExcelVersion = ExcelVersion.Excel97to2003;

        var excelEngine = grid.ExportToExcel(grid.View, option);

        var workBook = excelEngine.Excel.Workbooks[0];               

        workBook.Worksheets[0].Pictures.AddPicture(20,1,jpgimage);

        SaveFileDialog sfd = new SaveFileDialog

        {

            FilterIndex = 2,

            Filter = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx"

        };

        if (sfd.ShowDialog() == true)

        {

            using (Stream stream = sfd.OpenFile())

            {

                if (sfd.FilterIndex == 1)

                    workBook.Version = ExcelVersion.Excel97to2003;

                else

                    workBook.Version = ExcelVersion.Excel2010;

                workBook.SaveAs(stream);

            }

            //Message box confirmation to view the created spreadsheet.

            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",

                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)

            {

                //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]

                System.Diagnostics.Process.Start(sfd.FileName);

            }

        }

    }

    catch (Exception)

    {

           

    }       
}


Please let us know if this solution helps you .

Regards,
Akila R.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;