OWC11控件的安装

最近做一个项目,需要生成一些报表,OWC是比较合适的组件,但是一直找不到新的安装教程,最后终于摸索出来了,分享一下。

 

这个文章适合的是vs2005+office2003+c# asp.net ,至于其他版本,应该稍做变通即可!

 

首先是安装条件:

1.正常工作的vs2005

2.office2003套装

3.还有可能要下载一个OWC组件

下载地址:http://www.microsoft.com/downloads/details.aspx?FamilyID=7287252c-402e-4f72-97a5-e0fd290d4b76&DisplayLang=zh-cn

 

安装步骤

1.vs2005中新建网站

2.添加OWC引用

vs2005服务资源管理器里右键点击网站主目录一行,添加引用,找到 Microsoft Office Web ComponentsOWC11)。

3.网站-添加新项

什么都不写,直接在浏览器测试,看能不能加载OWC组件。如果可以直接跳到第五步。如果提示缺少必要的什么东东,就做第四步吧。

4.安装OWC11组件(就是在准备里让下载的那个,微软网站可以免费下载,不过电脑要装office2003才能装上哦)。安装之后重复第三步看看。

5.制作我的第一个OWC

复制以下代码到你的页面的.cs代码的page_load中,在设计里拖进来一个图片空间Image1,保存测试你的网页。

//创建ChartSpace对象来放置图表

Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass ();

 

//ChartSpace对象中添加图表,Add方法返回chart对象

Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add (0);

 

//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到

objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;

 

//指定图表是否需要图例

objChart.HasLegend = true;

 

//给定标题

objChart.HasTitle = true;

objChart.Title.Caption= "上半年分布图";

 

//给定x,y轴的图示说明

objChart.Axes[0].HasTitle = true;

objChart.Axes[0].Title.Caption = "Y 数量";

objChart.Axes[1].HasTitle = true;

objChart.Axes[1].Scaling.SplitMinimum  = 200;

objChart.Axes[1].Title.Caption = "X 月份";

 

//计算数据

/*categories values 可以用tab分割的字符串来表示*/

string strSeriesName = "图例 1";

string strCategory = "1" + "/t" + "2" + '/t' + "3" + '/t'+"4" + '/t' + "5" + '/t' + "6" + '/t';

string strValue = "9" + "/t" + "8" + '/t' + "4" + '/t'+"10" + '/t' + "12" + '/t' + "6" + '/t';

 

//添加一个series

objChart.SeriesCollection.Add(0);

 

//给定series的名字

objChart.SeriesCollection[0].SetData (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,

+ (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

 

//给定分类

objChart.SeriesCollection[0].SetData (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,

+ (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);

 

//给定值

objChart.SeriesCollection[0].SetData

(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,

(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);

//输出成GIF文件.

string strAbsolutePath = (Server.MapPath(".")) + "//test.gif";

objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 350);

 

//创建GIF文件的相对路径.

string strRelativePath = "./test.gif";

 

//把图片添加到placeholder.

//string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";

//ChartHolder.Controls.Add(new LiteralControl(strImageTag));

Image1.ImageUrl=strRelativePath;

 

 

 

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/tuwen/archive/2009/03/16/3994532.aspx

Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. 收藏 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [COMException (0x80040154): Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.] GraphPage.Page_Load(Object sender, EventArgs e) +1097 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 请大家帮忙 谢谢 Server Error in '/' Application. -------------------------------------------------------------------------------- Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值