Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I have a winform chart in C# and I would like to export this into excel, preferably so that I can edit or whatever in excel. I found an example on how to export it as a GIF file, but that is not what I want.

Hopefully someone is able to help :)

Thx
Posted
Comments
thatraja 6-Nov-13 7:54am    
winform chart? what's that? MS chart?
Handyman83 6-Nov-13 8:53am    
A data chart where you present statistic in e.g columns or line.
thatraja 6-Nov-13 9:03am    
data chart? No idea. For charts, I did use Crystal reports & MS Chart. So which component you're using for chart. Complete details please
Handyman83 6-Nov-13 10:24am    
I really dont understand What you want to know. I have a window popping up with a chart on it displaying fuel consumption on the y axis and days of month on the x axis. Now I want a button to export this into an MS excel spreadsheet.
thatraja 6-Nov-13 10:34am    
My mistake, I should have you for the code. Actually I didn't know that winform(new version) has chart option. That's why I asked you about component details. I'm not a winform developer. So right solutions from me now. I'll try to come here later. Alternatively you could try this one. How to create Excel Chart from C#

Hello Handyman83,

As far as I know, what you are trying to do would be possible only if you build the chart through sending c# data to an excel spreadsheet. I've done some research and found this link http://csharp.net-informations.com/excel/csharp-excel-chart.htm[^]. I hope it will help you with your needs.

Good Luck,
 
Share this answer
 
It is not clear from your question exactly what you want to do. It sounds like, since you don't want to copy a image (gif file) to Excel that what you want is to copy the data that is in the chart into an Excel spreadsheet.
One way of transferring data from a C# program to Excel is to save the data to a CSV file. A CSV file (Comma-Separated Values) can be opened by Excel.
At this link[^] are some basic examples of exporting data to a CSV file.

You don't specify which version of Excel you are working with, but if it is from Office 2007 or later you can use the Open XML SDK[^]. CodeProject even has an article[^] about how to use this SDK.

If you want your code to create an actual chart in Excel that is also possible. Take a look at this link[^] to get started.

After you have written some code to transfer the data and you get stuck feel free to ask questions here. Include the code you have written so far as well as a detailed description of any error messages.
 
Share this answer
 
Comments
Handyman83 7-Nov-13 7:59am    
Thank you, this looks like it could be much appreciated help. I have written some code, but at this point I would like to try a little more by myself. Right now I am struggling with my sql query. All my information is in a database. I'll get back to you after I have tried a little more.

great help! thx
BillW33 7-Nov-13 9:02am    
You are very welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900