Chart Data Source from Spreadsheet in C#

D

Dave.T

I am trying to use the chart space data source property to get data from
a spreadsheet using c#. Microsoft has an example on the net in VB but I
can't get my interpretation to work in c#.

In VB: ChartSpace1.DataSource = Spreadsheet1

In c# I tried:
axChartSpace1.DataSource = (msdatasrc.DataSource) axSpreadsheet1;
which compiles but produce an system invalid exception when run.

Can someone shed some light on what I am doing wrong.

Thanks
Dave.T
 
A

Alvin Bruney [Microsoft MVP]

If memory serves me correct (i don't have the code in front of me), you will
need to specify the excel range that the chart will source its data from
otherwise it won't know what to use.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
 
D

Dave.T

Dear Alvin,
After receiving your Black Book, I tried dynamic binding of the
spreadsheet as illustrated on Page 152. I still receive
'System.InvalidCastException' error. Any help would be appreciated.

Dave.T
 
A

Alvin Bruney [Microsoft MVP]

This should be working for you. How about cutting this code and pasting it
in.

OWC11.SpreadsheetClass xlsheet = new SpreadsheetClass();
xlsheet.ActiveSheet.Cells[1,1] = "Item";
xlsheet.ActiveSheet.Cells[1,2] = "1";
xlsheet.ActiveSheet.Cells[2,2] = "2";
xlsheet.ActiveSheet.Cells[2,2] = "3";

oChartSpace.DataSource = (msdatasrc.DataSource)(object)xlsheet;

oChartSpace.Charts[0].SeriesCollection[0].SetData
(OWC11.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum. chDataBound), "A1:B6");

This is for in-memory object by the way, but you should be able to adjust it
to make it work for script if that is where the problem is occuring
--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
 
J

Juan burelo

hi can u send to my mail([email protected]) the entire code please, because
it break's in the last line, i dont know what is the problem, please help me.


i hope u can send it because i relly need this.

tnks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top