在Web app中,若要使用ActiveX控件的话,不用自己createobject,(在项目引用中添加对此COM组件的引用,对控件不用这一步),然后在工具箱中加入该COM控件,再把该控件拖到WEB窗体上就行了,vs.net会帮你做好一切。如下面是在页面中拖入Excel表格控件后自动生成的页面代码:<%@ Page language="c#" Codebehind="ComTest.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.ComTest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ComText</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="ComText" method="post" runat="server">
<OBJECT style="Z-INDEX: 101; LEFT: 74px; POSITION: absolute; TOP: 39px" classid="clsid:0002E510-0000-0000-C000-000000000046">
<PARAM NAME="HTMLURL" VALUE="">
<PARAM NAME="HTMLData" VALUE="<html xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <style type="text/css"> <!--tr 	{mso-height-source:auto;} td 	{white-space:nowrap;} .wc819D1A81 	{white-space:nowrap; 	font-family:宋体; 	mso-number-format:General; 	font-size:auto; 	font-weight:auto; 	font-style:auto; 	text-decoration:auto; 	mso-background-source:auto; 	mso-pattern:auto; 	mso-color-source:auto; 	text-align:general; 	vertical-align:bottom; 	border-top:none; 	border-left:none; 	border-right:none; 	border-bottom:none; 	mso-protection:locked;} --> </style> </head> <body> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:OWCVersion>9.0.0.3821</x:OWCVersion> <x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver; border-right:solid .5pt silver;border-bottom:solid .5pt silver'> <x:Caption>Microsoft Office Spreadsheet</x:Caption> </x:Label> <x:Name>Sheet1</x:Name> <x:WorksheetOptions> <x:Selected/> <x:Height>7620</x:Height> <x:Width>15240</x:Width> <x:TopRowVisible>0</x:TopRowVisible> <x:LeftColumnVisible>0</x:LeftColumnVisible> <x:ProtectContents>False</x:ProtectContents> <x:DefaultRowHeight>210</x:DefaultRowHeight> <x:StandardWidth>2389</x:StandardWidth> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> <x:MaxHeight>80%</x:MaxHeight> <x:MaxWidth>80%</x:MaxWidth> </x:ExcelWorkbook> </xml><![endif]--> <table class=wc819D1A81 x:str> <col class=wc819D1A81 width="56"> <tr height="14"> <td class=wc819D1A81></td> </tr> </table> </body> </html> ">
<PARAM NAME="DataType" VALUE="HTMLDATA">
<PARAM NAME="AutoFit" VALUE="0">
<PARAM NAME="DisplayColHeaders" VALUE="-1">
<PARAM NAME="DisplayGridlines" VALUE="-1">
<PARAM NAME="DisplayHorizontalScrollBar" VALUE="-1">
<PARAM NAME="DisplayRowHeaders" VALUE="-1">
<PARAM NAME="DisplayTitleBar" VALUE="-1">
<PARAM NAME="DisplayToolbar" VALUE="-1">
<PARAM NAME="DisplayVerticalScrollBar" VALUE="-1">
<PARAM NAME="EnableAutoCalculate" VALUE="-1">
<PARAM NAME="EnableEvents" VALUE="-1">
<PARAM NAME="MoveAfterReturn" VALUE="-1">
<PARAM NAME="MoveAfterReturnDirection" VALUE="0">
<PARAM NAME="RightToLeft" VALUE="0">
<PARAM NAME="ViewableRange" VALUE="1:65536">
</OBJECT>
</form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ComText</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="ComText" method="post" runat="server">
<OBJECT style="Z-INDEX: 101; LEFT: 74px; POSITION: absolute; TOP: 39px" classid="clsid:0002E510-0000-0000-C000-000000000046">
<PARAM NAME="HTMLURL" VALUE="">
<PARAM NAME="HTMLData" VALUE="<html xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <style type="text/css"> <!--tr 	{mso-height-source:auto;} td 	{white-space:nowrap;} .wc819D1A81 	{white-space:nowrap; 	font-family:宋体; 	mso-number-format:General; 	font-size:auto; 	font-weight:auto; 	font-style:auto; 	text-decoration:auto; 	mso-background-source:auto; 	mso-pattern:auto; 	mso-color-source:auto; 	text-align:general; 	vertical-align:bottom; 	border-top:none; 	border-left:none; 	border-right:none; 	border-bottom:none; 	mso-protection:locked;} --> </style> </head> <body> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:OWCVersion>9.0.0.3821</x:OWCVersion> <x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver; border-right:solid .5pt silver;border-bottom:solid .5pt silver'> <x:Caption>Microsoft Office Spreadsheet</x:Caption> </x:Label> <x:Name>Sheet1</x:Name> <x:WorksheetOptions> <x:Selected/> <x:Height>7620</x:Height> <x:Width>15240</x:Width> <x:TopRowVisible>0</x:TopRowVisible> <x:LeftColumnVisible>0</x:LeftColumnVisible> <x:ProtectContents>False</x:ProtectContents> <x:DefaultRowHeight>210</x:DefaultRowHeight> <x:StandardWidth>2389</x:StandardWidth> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> <x:MaxHeight>80%</x:MaxHeight> <x:MaxWidth>80%</x:MaxWidth> </x:ExcelWorkbook> </xml><![endif]--> <table class=wc819D1A81 x:str> <col class=wc819D1A81 width="56"> <tr height="14"> <td class=wc819D1A81></td> </tr> </table> </body> </html> ">
<PARAM NAME="DataType" VALUE="HTMLDATA">
<PARAM NAME="AutoFit" VALUE="0">
<PARAM NAME="DisplayColHeaders" VALUE="-1">
<PARAM NAME="DisplayGridlines" VALUE="-1">
<PARAM NAME="DisplayHorizontalScrollBar" VALUE="-1">
<PARAM NAME="DisplayRowHeaders" VALUE="-1">
<PARAM NAME="DisplayTitleBar" VALUE="-1">
<PARAM NAME="DisplayToolbar" VALUE="-1">
<PARAM NAME="DisplayVerticalScrollBar" VALUE="-1">
<PARAM NAME="EnableAutoCalculate" VALUE="-1">
<PARAM NAME="EnableEvents" VALUE="-1">
<PARAM NAME="MoveAfterReturn" VALUE="-1">
<PARAM NAME="MoveAfterReturnDirection" VALUE="0">
<PARAM NAME="RightToLeft" VALUE="0">
<PARAM NAME="ViewableRange" VALUE="1:65536">
</OBJECT>
</form>
</body>
</HTML>
Object MyObject;
MyObject = Server.CreateObject("Acme.Component.3");
你可以在项目中添加这个组件的引用,然后和使用其他类一样在程序中实例化他。