Repost : Urgent : Programmatically add a COM object from code-behind into a web form

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi all,

I did post this about 10 hours ago thinking I would have received an answer
now but it is quite urgent.

How do I add a COM object to a web form?

I notice there's a primary interop assembly for Office web components and
what I'm trying to do here is to create a PivotTable object (which is fine)
but then I want to add it to a web page (e.g.
Page.Controls.Add(COMPivotTable)).

I receive the following error message but don't understand what I need to do
to correct this:
"Unable to cast COM object of type
'Microsoft.Office.Interop.Owc11.PivotTableClass' to class type
'System.Web.UI.Control'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however they
can be cast to interfaces as long as the underlying COM component supports
QueryInterface calls for the IID of the interface."

Any ideas?

Regards
John.
 
Hi John,

You're mixing client-side code and server-side (ASP.NET) code in a way that
doesn't work.

What you want is to have the Office component appear inside Internet
Explorer, right?

Therefore, your page needs to output client-side script that will use the
PivotTable object that must already exist on the user's machine. Here's how
the resulting browser code might look:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<p>
<object classid="clsid:0002E55A-0000-0000-C000-000000000046"
id="PivotTable1">
<param name="XMLData" value="&lt;xml
xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;&gt;
&lt;x:PivotTable&gt;
&lt;x:OWCVersion&gt;11.0.0.6555 &lt;/x:OWCVersion&gt;
&lt;x:DisplayScreenTips/&gt;
&lt;x:CubeProvider&gt;msolap.2&lt;/x:CubeProvider&gt;
&lt;x:CacheDetails/&gt;
&lt;x:PivotView&gt;
&lt;x:IsNotFiltered/&gt;
&lt;/x:PivotView&gt;
&lt;/x:PivotTable&gt;
&lt;/xml&gt;">
<table width='100%' cellpadding='0' cellspacing='0' border='0'
height='8'><tr><td bgColor='#336699' height='25' width='10%'>&nbsp;</td><td
bgColor='#666666'width='85%'><font face='Tahoma' color='white'
size='4'><b>&nbsp; Missing: Microsoft Office Web
Components</b></font></td></tr><tr><td bgColor='#cccccc'
width='15'>&nbsp;</td><td bgColor='#cccccc' width='500px'><br> <font
face='Tahoma' size='2'>This page requires the Microsoft Office Web
Components.<p align='center'> <a href='Z:/files/owc11/setup.exe'>Click here
to install Microsoft Office Web Components.</a>.</p></font><p><font
face='Tahoma' size='2'>This page also requires Microsoft Internet Explorer
5.01 or higher.</p><p align='center'><a
href='http://www.microsoft.com/windows/ie/default.htm'> Click here to
install the latest Internet
Explorer</a>.</font><br>&nbsp;</td></tr></table></object>
</p>

</body>

</html>
 
Back
Top