根據項目需要,最近在做一個關于owc透視表的功能(PivotTable),這個東西啊讓我可是郁悶了將近10天,網上很多資源都是直接連接數據源的方式,但對于實現系統開發來說,不實用,因為b/s系統多數是分層架構,并且部署實施時,很難由客戶端直接向數據庫服務器發出請求。原因就不多說了。
確定的解決方案是:
1.數據庫后臺組織數據和透視表展現樣式
2.通過action將數據發到前端。
3.在前臺通過ADODB.Recordset,msxml2.domdocument這兩個對象加載數據
下面給出xml文件格式(這可是我在目前網上沒找到的哦,也是最初困惑我的一方面)
 1<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
 2    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
 3    xmlns:rs='urn:schemas-microsoft-com:rowset'
 4    xmlns:z='#RowsetSchema'>
 5<s:Schema id='RowsetSchema'>
 6<s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
 7<s:AttributeType name='name' rs:number='1' rs:writeunknown='true'>
 8<s:datatype dt:type='string' dt:maxLength='100' rs:maybenull='true'/>
 9</s:AttributeType>
10<s:AttributeType name='class' rs:number='2' rs:writeunknown='true'>
11<s:datatype dt:type='string' dt:maxLength='100' rs:maybenull='true'/>
12</s:AttributeType>
13<s:AttributeType name='score' rs:number='3' rs:writeunknown='true'>
14<s:datatype dt:type='int' dt:maxLength='100' rs:maybenull='true'/>
15</s:AttributeType>
16<s:extends type='rs:rowbase'/>
17</s:ElementType>
18</s:Schema>
19<rs:data>
20<z:row name='hill' class='1' score='10' />
21<z:row name='hill' class='2' score='20' />
22<z:row name='zuo' class='1' score='30' />
23<z:row name='zuo' class='2' score='40' />
24</rs:data>
25</xml>
這個xml只是一個小例子,可以按照這樣的格式由程序動態生成,或是在數據庫端以函數形式組織(這個方面好,尤其是數據量大且復雜的情況)
下面給出如何加載數據:
 1 //聲明RecordSet對象
 2        var adors = new ActiveXObject("ADODB.Recordset");
 3        //alert(adors);
 4        //聲明XMLDocument對象
 5        //TODO:msxml2.domdocument有可能是msxml3.domdocument或msxml4.domdocument,有待證明
 6        var xmldoc = new ActiveXObject("msxml2.domdocument");
 7        //alert(xmldoc);
 8        //服務器端返回的XML字符串,用來構造RecordSet
 9        var str="<%=xml%>";
10        
11        //XMLDocument對象加載XML字符串
12        xmldoc.loadXML(str);
13        
14        //RecordSet設定數據源為上面的XMLDocument對象,并打開
15        adors.Open(xmldoc);
16        
17        pvt = document.PivotTable1;
18        
19        pvtconstants = pvt.Constants;
20        //設定透視表的數據源為上面的RecordSet對象
21        pvt.DataSource = adors;
其中的xml變更為從action發到前臺的xml數據
基本上這樣就可以應用了。有不同觀點的,愿意和你們一起交流

開心過好每一天。。。。。