Skip to content

DevExpress-Examples/winforms-charts-export-chart-to-xls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chart for WinForms - Export a Chart to XLS

The following example exports a chart as an image to an XLS document. In this example, the form contains the Export to File and Export to Stream buttons that allow you to save the XLS document with the chart image to a file or a stream.

Follow the steps below to implement this scenario:

  1. Add a Chart Control object to the form. Make sure that the Chart Control Name is chartControl1 in the Visual Studio Properties window. For more information, see the following topic: How to: Add a Chart to a Windows Forms Application.

  2. Create a Series object in the Form1_Load event handler. Use the ChartControl.Series.Add method to add this series to the chart.

  3. Specify the ChartControl.DataSource, Series.ArgumentDataMember, and Series.ValueDataMembers properties to populate the chart with data. In this example, the GetSales method returns the chart data source.

  4. Add two SimpleButtons to the form. Set the first button's Text property to Export to File and the second button's property to Export to Stream.

  5. The Chart Control uses the DevExpress Printing Library to export a chart. To use this library, add references to the following assemblies to the project:

    • DevExpress.XtraPrinting.XX.X,
    • DevExpress.Printing.vXX.X.Core.
  6. Handle the first button's Click event and use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported. Call the ChartControl.ExportToXls(System.String) method to export the chart to a file. Pass the path to this file as a parameter to this method.

  7. Handle the second button's Click event and use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported. Call the ChartControl.ExportToXls(System.IO.Stream) method to export the chart to a stream. This example uses FileStream, and you can open the file where the stream is saved to check the export result.

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Export a DevExpress WinForms chart as an image to an XLS document

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •