I'm trying to write a program to create a chart in excel by C#.
I've wrote the program and it work correctly in win7pro and Office 2007
but when I execute the program in a system with windows XP sp(3) and office 2003 it throws below error:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
at Microsoft.Office.Interop.Excel._Chart.ChartWizard(Object Source, Object Gallery, Object Format, Object PlotBy, Object CategoryLabels, Object SeriesLabels, Object HasLegend, Object Title, Object CategoryTitle, Object ValueTitle, Object
ExtraTitle)
at ConsoleApplication2.Report.createChart(Worksheet ws, String chartTitle, String xName, String yName)
at ConsoleApplication2.Report.createReport(List`1 data, String chartTitle, String xName, String yName)
at CreateExcelWorksheet.Main()
the code which create chart for me is below:
protected void createChart(Worksheet ws,string chartTitle,string xName,string yName)
{
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 10, 300, 300);
Chart xlChart = chartObj.Chart;
Range rg;
rg = ws.get_Range(startCell,endCell);
xlChart.ChartWizard(rg, XlChartType.xlXYScatterSmooth, 1, XlRowCol.xlColumns, 0, 0, true, chartTitle, xName, yName, "");
}
and the error line is the last one.
does anyone know what should I do?
in addition when I replace the last line with following lines the program works but I need to set some properties like xName and yName and ChartTitle for chart. does anyone know how can I do that?
xlChart.ChartType = XlChartType.xlXYScatterSmoothNoMarkers;
xlChart.SetSourceData(rg, Type.Missing);
thank you