Office Data Connection (.odc) 是 XML 格式的連線定義檔,包含提供者、連線字串、命令類型與命令文字。IE 透過 dataconn.htc 行為解析 ODC,直接在網頁呈現資料表格。
<html xmlns:odc="urn:schemas-microsoft-com:Office:odc">
<head>
<meta name="ProgId" content="ODC.Table">
<meta name="SourceType" content="OLEDB">
<meta name="Catalog" content="K0712">
<meta name="Schema" content="dbo">
<meta name="Table" content="T_Material">
<style>
.ODCDataSource { behavior: url(dataconn.htc); }
</style>
</head>
<body>
<xml id="msodc">
<odc:OfficeDataConnection xmlns:odc="urn:schemas-microsoft-com:Office:odc">
<odc:Connection odc:Type="OLEDB">
<odc:ConnectionString>
Provider=SQLOLEDB.1;Integrated Security=SSPI;
Persist Security Info=True;Data Source=develop;
Initial Catalog=K0712
</odc:ConnectionString>
<odc:CommandType>Table</odc:CommandType>
<odc:CommandText>"K0712"."dbo"."ICInventory"</odc:CommandText>
</odc:Connection>
</odc:OfficeDataConnection>
</xml>
<table class="ODCDataSource" datasrc="#msodc" border="1">
<thead><tr><th>欄位</th></tr></thead>
<tbody><tr><td><span datafld="*"></span></td></tr></tbody>
</table>
</body>
</html>
| 屬性 | 說明 | 範例 |
|---|---|---|
odc:ConnectionString |
標準 OLE DB 連線字串 | Provider=SQLOLEDB.1;Integrated Security=SSPI;Data Source=.;Initial Catalog=MyDB |
odc:CommandType |
Table / SQL |
Table 直接指定表名;SQL 可寫完整 SELECT |
odc:CommandText |
表名或 SQL 文字 | "MyDB"."dbo"."Orders" 或 SELECT * FROM Orders WHERE Date > '2024-01-01' |
dataconn.htc 才可用。TOP 或分頁視圖。