创建 Office 数据连接文件Create an Office Data Connection file

本文中的信息描述了如何创建 Office Data Connection 文件,以从 Excel 2016 版本号 16.0.7369.2117 或更早版本或 Excel 2013 连接到 Azure Analysis Services 服务器。Information in this article describes how you can create an Office Data Connection file to connect to an Azure Analysis Services server from Excel 2016 version number 16.0.7369.2117 or earlier, or Excel 2013. 还需要更新的 MSOLAP.7 提供程序An updated MSOLAP.7 provider is also required.

  1. 复制下面的示例连接文件,并粘贴到文本编辑器中。Copy the sample connection file below and paste into a text editor.

  2. odc:ConnectionString 中,更改以下属性:In odc:ConnectionString, change the following properties:

    • Data Source=asazure://<region>.asazure.chinacloudapi.cn/<servername>; 中,将 <region> 更改为你 Analysis Services 服务器的区域,将 <servername> 更改为你服务器的名称。In Data Source=asazure://<region>.asazure.chinacloudapi.cn/<servername>; change <region> to the region of your Analysis Services server and <servername> to the name of your server.

    • Initial Catalog=<database>; 中,将 <database> 更改为你数据库的名称。In Initial Catalog=<database>; change <database> to the name of your database.

  3. <odc:CommandText>Model</odc:CommandText> 中,将 Model 更改为你的模型或者视角的名称。In <odc:CommandText>Model</odc:CommandText> change Model to the name of your model or perspective.

  4. 将带有 .odc 扩展名的文件保存到 C:\Users\username\Documents\My Data Sources 文件夹。Save the file with an .odc extension to the C:\Users\username\Documents\My Data Sources folder.

  5. 右键单击该文件,并单击“在 Excel 中打开”。Right-click the file, and then click Open in Excel. 或者在 Excel 的“数据”功能区上,单击“现有连接”,选择文件,然后单击“打开”。Or in Excel, on the Data ribbon, click Existing Connections, select your file, and then click Open.

示例连接文件Sample connection file

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns="https://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/x-ms-odc; charset=utf-8">
<meta name=ProgId content=ODC.Cube>
<meta name=SourceType content=OLEDB>
<meta name=Catalog content="Database">
<meta name=Table content=Model>
<title>AzureAnalysisServicesConnection</title>
<xml id=docprops><o:DocumentProperties
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns="https://www.w3.org/TR/REC-html40">
  <o:Name>SampleAzureAnalysisServices</o:Name>
 </o:DocumentProperties>
</xml><xml id=msodc><odc:OfficeDataConnection
  xmlns:odc="urn:schemas-microsoft-com:office:odc"
  xmlns="https://www.w3.org/TR/REC-html40">
  <odc:Connection odc:Type="OLEDB">
   <odc:ConnectionString>Provider=MSOLAP.7;Data Source=asazure://<region>.asazure.chinacloudapi.cn/<servername>;Initial Catalog=<database>;</odc:ConnectionString>
   <odc:CommandType>Cube</odc:CommandType>
   <odc:CommandText>Model</odc:CommandText>
  </odc:Connection>
 </odc:OfficeDataConnection>
</xml>
<style>
<!--
    .ODCDataSource
    {
    behavior: url(dataconn.htc);
    }
-->
</style>

</head>

<body onload='init()' scroll=no leftmargin=0 topmargin=0 rightmargin=0 style='border: 0px'>
<table style='border: solid 1px threedface; height: 100%; width: 100%' cellpadding=0 cellspacing=0 width='100%'> 
  <tr> 
    <td id=tdName style='font-family:arial; font-size:medium; padding: 3px; background-color: threedface'> 
      &nbsp; 
    </td> 
     <td id=tdTableDropdown style='padding: 3px; background-color: threedface; vertical-align: top; padding-bottom: 3px'>

      &nbsp; 
    </td> 
  </tr> 
  <tr> 
    <td id=tdDesc colspan='2' style='border-bottom: 1px threedshadow solid; font-family: Arial; font-size: 1pt; padding: 2px; background-color: threedface'>

      &nbsp; 
    </td> 
  </tr> 
  <tr> 
    <td colspan='2' style='height: 100%; padding-bottom: 4px; border-top: 1px threedhighlight solid;'> 
      <div id='pt' style='height: 100%' class='ODCDataSource'></div> 
    </td> 
  </tr> 
</table> 

<script language='javascript'> 

function init() { 
  var sName, sDescription; 
  var i, j; 

  try { 
    sName = unescape(location.href) 

    i = sName.lastIndexOf(".") 
    if (i>=0) { sName = sName.substring(1, i); } 

    i = sName.lastIndexOf("/") 
    if (i>=0) { sName = sName.substring(i+1, sName.length); } 

    document.title = sName; 
    document.getElementById("tdName").innerText = sName; 

    sDescription = document.getElementById("docprops").innerHTML; 

    i = sDescription.indexOf("escription>") 
    if (i>=0) { j = sDescription.indexOf("escription>", i + 11); } 

    if (i>=0 && j >= 0) { 
      j = sDescription.lastIndexOf("</", j); 

      if (j>=0) { 
          sDescription = sDescription.substring(i+11, j); 
        if (sDescription != "") { 
            document.getElementById("tdDesc").style.fontSize="x-small"; 
          document.getElementById("tdDesc").innerHTML = sDescription; 
          } 
        } 
      } 
    } 
  catch(e) { 

    } 
  } 
</script> 

</body> 

</html>