Thanks for replying,
Quote:
Did you try this one ?
SeriesCollection.Item("1")
Yes
|
SeriesCollection sc =
(SeriesCollection)xlChart.SeriesCollection(Type.Mi ssing);
Series series = (Series)sc.Item("1") ;
Which causes a:
“
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in mscorlib.dll
Additional information: Item method of SeriesCollection class failed
“
This tells me nothing.
Alternatively I have tried:
Series series = (Series)xlChart.SeriesCollection("1");
Which throws an exception with an HRESULT:
“
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in ExcelTest.exe
Additional information: Exception from HRESULT: 0x800A03EC.
“
From what I could find on MSDN and Google, it appears that HRESULT
0x800A03EC is a pretty much useless.
My source code is:
private void set_up_and_do()
{
this.app = new Microsoft.Office.Interop.Excel.ApplicationClass();
this.work =
app.get_Workbooks().Open(System.Windows.Forms.Appl ication.get_StartupPath()+"\\default.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
xlSheet = (Worksheet)this.work.get_Worksheets().get_Item("Sh eet1");
write_system_headers(); //write column labels
write_system_labels(); //write row labels
write_arrays(); //write data arrays
Range rng = this.xlSheet.get_Range("D4","D"+j );//range where data was
written to
ChartObjects charts = (ChartObjects)xlSheet.ChartObjects(Type.Missing);
ChartObject chartObj = charts.Add(100,300,500,300);
Chart xlChart = chartObj.get_Chart();
xlChart.ChartWizard((Object)rng,(Object) Constants.xlColumn, Type.Missing,
(Object)XlRowCol.xlColumns,Type.Missing,Type.Missi ng, Type.Missing,
(Object)"Title", (Object)"Y Title", (Object)"X Title", (Object)"Extra
Title");
//get the series collection from the chart
SeriesCollection sc =
(SeriesCollection)xlChart.SeriesCollection(Type.Mi ssing);
//Series series = (Series)sc.Item( "1") ;
Series series = (Series)xlChart.SeriesCollection( "1");
}
It crashes on either of the last two lines.
btw, the Excel Microsoft.Office.Interop.Excel reference is for the
“Microsoft Excel 11.0 Object Library” version 1.5
From what I could glean from the few C# examples on Excel charts,
SeriesCollection() needs an integer object passed to it; and this is why I
asked my original question.
Might this be a flaw in the design of J#? I certainly hope that its just me
missing something simple.
Thanks,
Nate Laws