COMException on Chart activation

A

andriy

While trying to create a chart in Excel programmatically I am running
into a strange problem. I am trying to generate a line chart without
markers in ASP C# like so:

crt = ((ChartObjects)ws.ChartObjects(Missing.Value)).Add(200 /*Left*/,
300 /*Top*/, 900 /*Width*/, 500 /*Height*/).Chart;
sourceRange = ws.get_Range(startCell, endCell);
crt.ChartWizard(sourceRange, XlChartType.xlLine, Type.Missing,
XlRowCol.xlColumns, 1, 1, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
crt.ChartTitle.Text = "Unfiltered Bus Laod Curve";
crt.ProtectFormatting = false;
crt.Activate();

When the program hits crt.Activate(), it throws
System.Runtime.InteropServices.COMException (0x800A03EC): Exception
from HRESULT: 0x800A03EC at
Microsoft.Office.Interop.Excel._Chart.Activate()

However, if I comment this line is, the exception is not thrown and I
can see the chart, however the chart is not editable.

Also, even though the chart type is set xlLine, it contains markers.
How can I get rid of them?

Any suggestions would be more than welcome:)
 
N

Nicholas Paldino [.NET/C# MVP]

Just a few thoughts. First, do you have the ASPCompat flag set on your
page? Because you are doing COM interop, you have to set this flag so the
ASP.NET runtime can set the thread up properly for COM interop.

Also, if you can, you should NOT be using Excel in an ASP.NET
application if you can prevent it.
 
A

andriy

Thanks! I did not have the flag set. However, the application still
throws exceptions, even though the flag is set. What is interesting
the exception is now thrown only if I ask the Chartwizard to create
xlLineMarkers chart type but not xlLine. I will stick to using xlLine,
however, for some reason, xlLine still has markers on it. Perhaps, I
should start a separate thread with the question about how to get rid
of them...

Just a few thoughts. First, do you have the ASPCompat flag set on your
page? Because you are doing COM interop, you have to set this flag so the
ASP.NET runtime can set the thread up properly for COM interop.

Also, if you can, you should NOT be using Excel in an ASP.NET
application if you can prevent it.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


While trying to create a chart in Excel programmatically I am running
into a strange problem. I am trying to generate a line chart without
markers in ASP C# like so:
crt = ((ChartObjects)ws.ChartObjects(Missing.Value)).Add(200 /*Left*/,
300 /*Top*/, 900 /*Width*/, 500 /*Height*/).Chart;
sourceRange = ws.get_Range(startCell, endCell);
crt.ChartWizard(sourceRange, XlChartType.xlLine, Type.Missing,
XlRowCol.xlColumns, 1, 1, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
crt.ChartTitle.Text = "Unfiltered Bus Laod Curve";
crt.ProtectFormatting = false;
crt.Activate();
When the program hits crt.Activate(), it throws
System.Runtime.InteropServices.COMException (0x800A03EC): Exception
from HRESULT: 0x800A03EC at
Microsoft.Office.Interop.Excel._Chart.Activate()
However, if I comment this line is, the exception is not thrown and I
can see the chart, however the chart is not editable.
Also, even though the chart type is set xlLine, it contains markers.
How can I get rid of them?
Any suggestions would be more than welcome:)
 
A

andriy

Hi everyone, once again. I figured out how to get rid of data markers
on the xlLine chart.

Basically, the third parameter of the ChartWizard needs to be set to
2. Before, I had it set to Type.Missing.

Thanks for your replies, guys!
 

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