Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of -eVe-
-eVe-
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nasir Razzaq
How about exporting the picture of the chart from VB.NET?
That's not really an export to Excel, is it? To Paint maybe ;-)
 
>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.
Avatar of Juan Velasquez

ASKER

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
Do you mean that you want to return the chart object to the calling form instead of an image?
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.