• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1217
  • Last Modified:

Export a chart from vb.net application to excel

Hello,
One of the requirements for the application that I am developing is for the user to be able to export charts such as graphs from the application to Excel.  I'm thinking it might be easer to just recreate the graph in Excel from the vb.net application via automation using the underlying datatables of the chart. I'd like to get feedback on that approach.  Thanks
0
chtullu135
Asked:
chtullu135
  • 4
  • 4
  • 2
2 Solutions
 
-eVe-Commented:
Sure, that's the way! Check this sample:
http://www.codeproject.com/KB/office/Excel_Automation.aspx
0
 
CodeCruiserCommented:
How about exporting the picture of the chart from VB.NET?
0
 
-eVe-Commented:
That's not really an export to Excel, is it? To Paint maybe ;-)
 
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CodeCruiserCommented:
>That's not really an export to Excel, is it? To Paint maybe ;-)

Actually, my idea was to capture the app output of the chart into an image file and then add that image file to the Excel spreadsheet.
0
 
chtullu135Author Commented:
Hello,
I've been thinking over both approaches and I think I will use both.  When a user wants to add a graph, the user click a button and the GraphDesigner form comes up.  The user then select the dataset and metrics to be graphed and the graph as well as the underlying dataset appears in the form.  If the user elects to add that graph, the user clicks okay and the user is then returned to the previous form where the graph will appear on the form (as image)  with the underlying datatable.  If the user want to print the results to excel, then the datatables are used to reconstruct the graph in the Excel worksheet and the dataset will appear below the graph.  I want to give  users to be able to interact with the graph when it is in Excel.  I could use the image on the form and use automation to create the graph for the excel sheet.  
Come to think of it, the graph in the preview pane is a charting control, why not just pass it as a cihart object to the form that displays the user selected charts.  I may be making things more complicated than they should be
0
 
CodeCruiserCommented:
Do you mean that you want to return the chart object to the calling form instead of an image?
0
 
chtullu135Author Commented:
I'm still depating whether or not to return the chart object or an image would be best.  I think it really is a matter of how much if any interaction the user needs to have with the chart in the calling form.
0
 
CodeCruiserCommented:
That is the basic deciding factor. If you do decide to return a chart object, either return a cloned object or keep the other form in memory. Because if you return a reference to the chart(default) and dispose the form, chart would be disposed as well.
0
 
chtullu135Author Commented:
I've just had a meeting with the client.  The user will not interact with the graph in the calling form, but will interact with it in the excel spreadsheet.  So given that, I will return the chart as a image to the calling form.  The calling form will also receive the underlying datatable.  I can then use automation to recreate the chart when the user elects to output the chart to excel.
0
 
chtullu135Author Commented:
The code at http://www.codeproject.com/KB/office/Excel_Automation.aspx was what I was looking for.  I'm in the process of modifying it.  I also appreciate code cruisers advice on using an image.  I will implement both solutions as I mentioned earlier.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now