OWC在展现时的翻译实现

在使用OWC的过程中,碰到连接CUBE时,数据库建的都是英文的,因为OWC直接通过OLAP连接了CUBE,所以,在“数据透视表字段列表”时展现的都是英文的,而我们的客户是中文的,所以需要在这个过程中建立一个翻译过程,当然,可能一般的CUBE创建时就使用了中文,我们这个工作有些无用,哈哈。反正实现了这个功能,记录一下。
在找这个翻译的过程中,花了很多时间,在这里记录一下。并且每段代码都是按照顺序执行,所以,按照整个顺序进行了代码整理。
整个翻译实现使用js哈希表和js操作XML文件方面的知识,代码整理如下:test.XML文件
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <DimIndex>
    <key>MC</key>
    <Name>商品名称</Name>
  </DimIndex>
  <DimIndex>
    <key>TXM</key>
    <Name>条形码</Name>
  </DimIndex>
</root>
在OWC的界面中JS加载XML文件的方法

<script language="javascript" type="text/javascript">
    function loadXMLDoc(dname) {
        var xmlDoc;
        // code for IE  
        if (window.ActiveXObject) {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        }
        // code for Mozilla, Firefox, Opera, etc.  
        else if (document.implementation && document.implementation.createDocument) {
            xmlDoc = document.implementation.createDocument("", "", null);
        }
        else {
            alert('加载XML文件时出错!');
        }
        xmlDoc.async = false;
        xmlDoc.load(dname);
        return (xmlDoc);
    }
  
</script>

然后在该界面面使用JS创建Hashtable对象的实现

<script language="JavaScript">
    //自定义哈希表类
    function Hashtable() {
        this._hash = new Object();  // 创建Object对象
        //哈希表的添加方法   
        this.add = function (key, value) {
            if (typeof (key) != "undefined") {
                if (this.contains(key) == false) {
                    this._hash[key] = typeof (value) == "undefined" ? null : value;
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        //哈希表的移除方法
        this.remove = function (key) { delete this._hash[key]; }
        //哈希表内部键的数量
        this.count = function () { var i = 0; for (var k in this._hash) { i++; } return i; }
        //通过键值获取哈希表的值
        this.items = function (key) { return this._hash[key]; }
        //在哈希表中判断某个值是否存在
        this.contains = function (key) { return typeof (this._hash[key]) != "undefined"; }
        //清空哈希表内容的方法
        this.clear = function () { for (var k in this._hash) { delete this._hash[k]; } }
    }
    var myhash = new Hashtable();                   //创建哈希表

    //初始化XML对象xmlDoc,文件名称test.xml
     var xmlDoc = loadXMLDoc("test.xml");
   
    var parent = xmlDoc.getElementsByTagName("root/DimIndex");
    var key = "";
    var val = "";
    for (var i = 0; i < parent.length; i++) {       
        key = parent[i].childNodes[0].text;
        val = parent[i].childNodes[1].text;
        myhash.add(key, val);
    }
</script>

在OWC创建连接之后,加入以下代码,实现翻译过程,
  //维度部分翻译
    for (var i = 0; i < pivotTable.ActiveView.FieldSets.Count; i++) {
        //列表项
        if (myhash.contains(pivotTable.ActiveView.FieldSets(i).Caption))
            pivotTable.ActiveView.FieldSets(i).Caption = myhash.items(pivotTable.ActiveView.FieldSets(i).Caption);
        for (var j = 0; j < pivotTable.ActiveView.FieldSets(i).Fields.Count; j++) {
            //列表内部
            if (myhash.contains(pivotTable.ActiveView.FieldSets(i).Fields(j).Caption))
                pivotTable.ActiveView.FieldSets(i).Fields(j).Caption = myhash.items(pivotTable.ActiveView.FieldSets(i).Fields(j).Caption);
        }
    }
    //汇总部分翻译
    for (var i = 0; i < pivotTable.ActiveView.Totals.Count; i++) {
        //列表项
        if (myhash.contains(pivotTable.ActiveView.Totals(i).Caption))
            pivotTable.ActiveView.Totals(i).Caption = myhash.items(pivotTable.ActiveView.Totals(i).Caption);
    }
界面使用OWC的HTML代码部分.
<object id="CSpace" classid="clsid:0002E556-0000-0000-C000-000000000046" width="95%"
        height="55%">
        <table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td bgcolor="#336699" height="25" width="10%">
                    &nbsp;
                </td>
                <td bgcolor="#666666" width="85%">
                    <font face="宋体" color="white" size="4"><b>缺少Web组件</b> </font>
                </td>
            </tr>
            <tr>
                <td bgcolor="#cccccc" width="15">
                    &nbsp;
                </td>
                <td bgcolor="#cccccc" width="500px">
                    <br>
                    <font face="宋体" size="2">此网页要求Web组件。
                        <p align="center">
                            <a href="OWC/OLAP.EXE">单击此处安装Web组件。</a>.
                        </p>
                    </font>
                    <p>
                        <font face="宋体" size="2">此网页同时要求 Microsoft Internet Explorer 5.01 或更高版本。</p>
                    <p align="center" />
                    <a href="http://www.microsoft.com/windows/ie/default.htm">单击此处安装最新的 Internet Explorer。</a>
                    </font><br>
                    &nbsp;
                </td>
            </tr>
        </table>
    </object>
    <object id="pivotTable" classid="clsid:0002E552-0000-0000-C000-000000000046" width="95%"
        height="40%">
        <param name="AutoFit" value="false" />
        <table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td bgcolor="#336699" height="25" width="10%">
                    &nbsp;
                </td>
                <td bgcolor="#666666" width="85%">
                    <font face="宋体" color="white" size="4"><b>缺少Web组件</b> </font>
                </td>
            </tr>
            <tr>
                <td bgcolor="#cccccc" width="15">
                    &nbsp;
                </td>
                <td bgcolor="#cccccc" width="500px">
                    <br>
                    <font face="宋体" size="2">此网页要求Web组件。
                        <p align="center">
                            <a href="OWC/OLAP.EXE">单击此处安装Web组件。</a>.
                        </p>
                    </font>
                    <p>
                        <font face="宋体" size="2">此网页同时要求 Microsoft Internet Explorer 5.01 或更高版本。</p>
                    <p align="center" />
                    <a href="http://www.microsoft.com/windows/ie/default.htm">单击此处安装最新的 Internet Explorer。</a>
                    </font><br>
                    &nbsp;
                </td>
            </tr>
        </table>
    </object>
下例代码实现OWC的连接OLAP的功能
 <script>
                document.all.pivotTable.ConnectionString = 'Provider=MSOLAP.4;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Adventure Works 2008R2;Data Source=http://localhost:8081/msmdpump.dll'
                document.all.pivotTable.DataMember = 'Adventure Works DW';
                document.all.pivotTable.DataMemberCaption ='维度分析';
                document.all.pivotTable.BackColor = 'Wheat';
                document.all.pivotTable.BorderColor ='LightBlue';

                document.all.pivotTable.DisplayFieldList =true;
                document.all.pivotTable.DisplayToolbar = true;
                document.all.pivotTable.DisplayExpandIndicator = true;
                document.all.pivotTable.DisplayAlerts = true;
                document.all.pivotTable.DisplayBranding = true;
                document.all.pivotTable.DisplayDesignTimeUI = false;
                document.all.pivotTable.DisplayFieldList = true;
                document.all.pivotTable.DisplayOfficeLogo = false;
  document.all.pivotTable.ActiveView.TitleBar.Visible = true;
                document.all.pivotTable.ActiveView.TitleBar.Caption = 'www.power-bi.com 智能分析工具';
                document.all.pivotTable.ActiveView.TitleBar.Font.Name = 'arial';
                document.all.pivotTable.ActiveView.TitleBar.Font.Size = 10;
                document.all.pivotTable.ActiveView.TitleBar.BackColor='blue';

                document.all.pivotTable.ActiveView.TotalBackColor = 'CornSilk';
                document.all.pivotTable.ActiveView.TotalFont.Name = 'arial';
                document.all.pivotTable.ActiveView.TotalFont.Size = 9;

                document.all.pivotTable.ActiveView.FieldLabelFont.Name = 'arial';
                document.all.pivotTable.ActiveView.FieldLabelFont.Size = 9;
                document.all.pivotTable.ActiveView.FieldLabelBackColor = 'Gold';

                document.all.pivotTable.ActiveView.HeaderFont.Name = 'arial';
                document.all.pivotTable.ActiveView.HeaderFont.Size = 9;
                document.all.pivotTable.ActiveView.HeaderBackColor = 'Gold';

                document.all.pivotTable.ActiveView.PropertyCaptionFont.Name = 'arial';
                document.all.pivotTable.ActiveView.PropertyCaptionFont.Size = 9;
                document.all.pivotTable.ActiveView.PropertyValueFont.Name = 'arial';
                document.all.pivotTable.ActiveView.PropertyValueFont.Size = 9;

                document.all.pivotTable.ActiveView.AllowAdditions = true;
                document.all.pivotTable.ActiveView.AllowDeletions = true;
                document.all.pivotTable.ActiveView.AllowEdits = true;

                document.all.pivotTable.ActiveView.ExpandMembers = document.all.pivotTable.Constants.plExpandNever;
                document.all.pivotTable.ActiveView.ExpandDetails = document.all.pivotTable.Constants.plExpandNever;


                 CSpace.DataSource = pivotTable;
                 CSpace.AllowPropertyToolbox = true;
                 CSpace.DisplayToolbar= true;
                 CSpace.DisplayOfficeLogo = false; //图隐藏微软图标
                 CSpace.Interior.Color ='LightBlue';
                 CSpace.Border.Color ='LightBlue';
                 CSpace.HasSelectionMarks = true;
                 CSpace.AllowPropertyToolbox = true;
                
                 CSpace.Charts(0).PlotArea.Interior.Color  ='Khaki';  //画图区域颜色
 </script>
以上代码实现了整个OWC在IE中展现数据拖拽功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

skey123123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值