由于项目中决定使用OWC,主要使用电子表格对象模型 和图表工作区对象模型,现在将使用过程学习到的一些东西记录下来,以备后用。
电子表格对象模型(Spreadsheet ),看起来跟Excel就是孪生兄弟,初步使用并不困难。
先看看下面一个实例,是不是非常easy:
<
html
xmlns:o
="urn:schemas-microsoft-com:office:office"
xmlns:x ="urn:schemas-microsoft-com:office:excel"
xmlns ="http://www.w3.org/TR/REC-html40" >
< head >
< meta http-equiv =Content-Type content ="text/html; charset=gb2312" >
< meta name =ProgId content =FrontPage.Editor.Document >
< meta name =Generator content ="Microsoft Excel 11" >
< title > Spreadsheet第一个实例 </ title >
</ head >
< script language ="javascript" > ...
function init() ...{
Spreadsheet1.ActiveSheet.Cells.Clear();
Spreadsheet1.ActiveSheet.Cells(2, 1).Value = "Car";
Spreadsheet1.ActiveSheet.Cells(3, 1).Value = "Sport-Utility";
Spreadsheet1.ActiveSheet.Cells(4, 1).Value = "Truck";
Spreadsheet1.ActiveSheet.Cells(5, 1).Value = "Minivan";
Spreadsheet1.ActiveSheet.Cells(1, 2).Value = "1998";
Spreadsheet1.ActiveSheet.Cells(2, 2).Value = 0.2;
Spreadsheet1.ActiveSheet.Cells(3, 2).Value = 0.06;
Spreadsheet1.ActiveSheet.Cells(4, 2).Value = 0.17;
Spreadsheet1.ActiveSheet.Cells(5, 2).Value = 0.13;
Spreadsheet1.ActiveSheet.Cells(1, 3).Value = "1999";
Spreadsheet1.ActiveSheet.Cells(2, 3).Value = 0.38;
Spreadsheet1.ActiveSheet.Cells(3, 3).Value = 0.82;
Spreadsheet1.ActiveSheet.Cells(4, 3).Value = 0.28;
Spreadsheet1.ActiveSheet.Cells(5, 3).Value = 0.62;
Spreadsheet1.ActiveSheet.Cells(1, 4).Value = "2000";
Spreadsheet1.ActiveSheet.Cells(2, 4).Value = 0.42;
Spreadsheet1.ActiveSheet.Cells(3, 4).Value = 0.12;
Spreadsheet1.ActiveSheet.Cells(4, 4).Value = 0.55;
Spreadsheet1.ActiveSheet.Cells(5, 4).Value = 0.25;
}
</ script >
< body onload ="init()" >
< b > Source: </ b > 行业数据——汽车工业 < p >
< object id =Spreadsheet1 classid =CLSID:0002E559-0000-0000-C000-000000000046 style ="width:100%;height:350" ></ object >
</ body >
</ html >
xmlns:x ="urn:schemas-microsoft-com:office:excel"
xmlns ="http://www.w3.org/TR/REC-html40" >
< head >
< meta http-equiv =Content-Type content ="text/html; charset=gb2312" >
< meta name =ProgId content =FrontPage.Editor.Document >
< meta name =Generator content ="Microsoft Excel 11" >
< title > Spreadsheet第一个实例 </ title >
</ head >
< script language ="javascript" > ...
function init() ...{
Spreadsheet1.ActiveSheet.Cells.Clear();
Spreadsheet1.ActiveSheet.Cells(2, 1).Value = "Car";
Spreadsheet1.ActiveSheet.Cells(3, 1).Value = "Sport-Utility";
Spreadsheet1.ActiveSheet.Cells(4, 1).Value = "Truck";
Spreadsheet1.ActiveSheet.Cells(5, 1).Value = "Minivan";
Spreadsheet1.ActiveSheet.Cells(1, 2).Value = "1998";
Spreadsheet1.ActiveSheet.Cells(2, 2).Value = 0.2;
Spreadsheet1.ActiveSheet.Cells(3, 2).Value = 0.06;
Spreadsheet1.ActiveSheet.Cells(4, 2).Value = 0.17;
Spreadsheet1.ActiveSheet.Cells(5, 2).Value = 0.13;
Spreadsheet1.ActiveSheet.Cells(1, 3).Value = "1999";
Spreadsheet1.ActiveSheet.Cells(2, 3).Value = 0.38;
Spreadsheet1.ActiveSheet.Cells(3, 3).Value = 0.82;
Spreadsheet1.ActiveSheet.Cells(4, 3).Value = 0.28;
Spreadsheet1.ActiveSheet.Cells(5, 3).Value = 0.62;
Spreadsheet1.ActiveSheet.Cells(1, 4).Value = "2000";
Spreadsheet1.ActiveSheet.Cells(2, 4).Value = 0.42;
Spreadsheet1.ActiveSheet.Cells(3, 4).Value = 0.12;
Spreadsheet1.ActiveSheet.Cells(4, 4).Value = 0.55;
Spreadsheet1.ActiveSheet.Cells(5, 4).Value = 0.25;
}
</ script >
< body onload ="init()" >
< b > Source: </ b > 行业数据——汽车工业 < p >
< object id =Spreadsheet1 classid =CLSID:0002E559-0000-0000-C000-000000000046 style ="width:100%;height:350" ></ object >
</ body >
</ html >
代码说明:
1. 要在html中使用电子表格对象,必须添加一个object对象,Spreadsheet 对象的编程标识符为 CLSID:0002E559-0000-0000-C000-000000000046(office2003版本,其他版本不同的clsid)
2. init方法是初始化电子表格内容。