Export multiple controls in a window to excel

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

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

1 Reply

AR Akila Rajaram Syncfusion Team 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.

Loader.
Up arrow icon